我有一种情况,我想使用$rootScope变量并用输入字段中输入的值更新它的值。我已将情景代码缩短为此DEMO:
HTML:
<div ng-controller="MyCtrl">
<input type="text" ng-model="foo" placeholder="Enter something" />
<input type="button" ng-click="doSomething()" value="Send" ng-disabled="foo == null" />
</div>
脚本:
var myApp = angular.module('myApp', []);
function MyCtrl($scope, $rootScope) {
$rootScope.foo = null;
$scope.doSomething = function () {
alert("Hello, " + $rootScope.foo);
}
}
关于如何将输入值传递给$rootScope变量的任何建议都会很棒!