更新时间:2023-02-16 16:43:21
更新答案:
由于不使用Angularjs路由,可以使用 ngInit
。它会在您的控制器的范围内初始化一个新的变量,你将能够访问它,如:
Since you are not using Angularjs routing, you can use ngInit
. It will initialize a new variable in your controller's scope and you will be able to access it like:
HTML(控制器内):
HTML (inside your controller):
<AnyElement ng-init="roomID = @ViewBag.roomID"></AnyElement>
JavaScript的:
JavaScript:
var roomID = $scope.roomID;
有关更多的解释请参见 ngInit文档。
For more explanations see ngInit documentation.
原来的答复:
在Angularjs你可以很方便地访问查询字符串参数,如:
In Angularjs you can access the query string parameter very easily like:
var paramValue = $routeParams.yourParameterName;
或者,如果你想要初始化一个JavaScript变量那么可以考虑使用 ngInit
。它会在您的控制器的范围内初始化一个新的变量,你将能够访问它,如:
Or if you want to initialize a JavaScript variable then consider using ngInit
. It will initialize a new variable in your controller's scope and you will be able to access it like:
HTML(控制器内):
HTML (inside your controller):
<AnyElement ng-init="roomID = @ViewBag.roomID"></AnyElement>
JavaScript的:
JavaScript:
var roomID = $scope.roomID;
有关更多的解释请参见 ngInit文档。
For more explanations see ngInit documentation.
希望有所帮助。