我是 Angular 的新手,已经通读了所有教程,但正处于学习曲线的陡峭点,这是我第一次构建真正的应用程序。
我只想在单击特定单选按钮时显示一个 div。
这是我的代码:
// HTML file
<label class="checkbox-inline">
<input type="radio" name="ast-adh-p1-radio" ng-model="value" ng-change='answerP1(value)' value="yes"> Yes
</label>
<label class="checkbox-inline">
<input type="radio" name="ast-adh-p1-radio" ng-model="value" ng-change='answerP1(value)' value="no"> No
</label>
<div ng-show="showQ1A">hello world </div>
// Controller file
angular
.module('adh.controllers', ['ngModel'])
.controller('adhCtrl', ['$scope', function ($scope) {
$scope.answerP1 = function(value) {
console.log('clicked radio button', value);
// change $scope.showQ1A accordingly
}
}]);
不幸的是,我收到以下错误,无法通过谷歌搜索解决:
Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:modulerr] Failed to instantiate module adh.controllers
due to:
Error: [$injector:modulerr] Failed to instantiate module ngModel due to:
Error: [$injector:nomod] Module 'ngModel' is not available! You either misspelled
the module name or forgot to load it. If registering a module ensure that you
specify the dependencies as the second argument.
我需要加载外部文件才能使用 ngModel
吗?我看不到这个 mentioned in the documentation .
如果是这样,是否有更简单的方法来做事?
最佳答案
没有名为 ngModel
的模块,删除该依赖项
angular
.module('adh.controllers',[])
.controller('adhCtrl', ['$scope', function ($scope) {
$scope.answerP1 = function(value) {
console.log('clicked radio button', value);
// change $scope.showQ1A accordingly
}
}]);
ngModel
是一个指令。
关于javascript - Angular 新手 : trying to use ng-change, 获取 "Module ' ngModel' 不可用”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19932915/