Html到$ scope还是$ rootScope?

时间:2016-06-03 13:22:09

标签: angularjs scope rootscope

想象一下,在HTML页面中,我有以下输入,而我没有使用controllerAs。

<input ng-model="password" type="password" placeholder="Password">

我可以在哪里访问$ scope或$ rootScope中的密码值?

我可以指定要输入模型信息的哪个?

2 个答案:

答案 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">