gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 16:14:08 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com