我是 AngularJS 的新手,并且确实有增强现有代码的任务。
简化后,以下内容位于 html 文件中:
<div class="popup-list" ng-controller="NumberCtrl">
First number: <input type="number" ng-init="$scope.firstNum">
</div>
我想在 JavaScript 文件中引用这一点:
angular.module('app').controller('NumberCtrl', function ($scope)
{
$scope.firstNum = 100
});
但是,会弹出模态窗口,提供输入字段,但没有预定义值 = 100。
这里出了什么问题?
最佳答案
您不需要在 view 中标记范围。
无论您在 View 中使用什么,它都会从 $scope
获取。
在输入控件中使用ng-model
来绑定(bind)数据。
像这样
First number: <input type="number" ng-model="firstNum">
您可能会在未设置的情况下获取模块。
尝试这样
angular.module('app',[]).controller
获取模块
angular.module('app')
设置模块
angular.module('app',[])
关于javascript - 'controller' 的 AngularJS 代码无法启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34836490/