想象一下,在HTML页面中,我有以下输入,而我没有使用controllerAs。
<input ng-model="password" type="password" placeholder="Password">
我可以在哪里访问$ scope或$ rootScope中的密码值?
我可以指定要输入模型信息的哪个?
答案 0 :(得分:2)
目前您正在引用$ scope。要定位$ rootScope,您应该使用:
<input ng-model="$root.password" type="password" placeholder="Password">
答案 1 :(得分:0)
要将变量绑定到rootScope,可以使用每个角度应用程序的ng-app指令提供:
<input ng-model="$rootScope.password" type="password" placeholder="Password">