javascript - Angular 新手 : trying to use ng-change, 获取 "Module ' ngModel' 不可用”?

标签 javascript angularjs

我是 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/

相关文章:

angularjs - Angular : Equivalent of ng:class for custom attributes?

javascript - 当日期匹配时使用 .Each 显示 Div

javascript - JS 单击事件捕获到 SVG 而不是按钮

javascript - Suitescript 1.0 - 获取销售订单中的行项目单位

javascript - react 错误: Target Container is not a DOM Element

javascript - 如何使用 AngularJs 将所有对象插入另一个数组

javascript - 在数组中查找重复数组

angularjs - ng-options 在具有预选值时不绑定(bind)

angularjs - 如何在 Angular/ ionic 网站上实现AMP?

javascript - 如何从 Chrome 的开发控制台检查来自 REST 端点的 JSON 响应?