【发布时间】:2016-06-03 21:30:59
【问题描述】:
想象一下,在一个 HTML 页面中,我有以下输入,但我没有使用 controllerAs。
<input ng-model="password" type="password" placeholder="Password">
我在哪里可以访问 $scope 或 $rootScope 中的 password 值?
我可以指定要输入哪些型号信息?
【问题讨论】:
想象一下,在一个 HTML 页面中,我有以下输入,但我没有使用 controllerAs。
<input ng-model="password" type="password" placeholder="Password">
我在哪里可以访问 $scope 或 $rootScope 中的 password 值?
我可以指定要输入哪些型号信息?
【问题讨论】:
目前您正在引用 $scope。对于定位 $rootScope,您应该使用:
<input ng-model="$root.password" type="password" placeholder="Password">
【讨论】:
要将变量绑定到 rootScope,它由您可以使用的每个 Angular 应用程序的 ng-app 指令提供:
<input ng-model="$rootScope.password" type="password" placeholder="Password">
【讨论】: