<select id = "email_templates" name = "email_templates" class="chosen-select input-md form-control" ng-change = "alert('template selected');">
<option value="0">No template selected</option>
<option value="1">Template 1</option>
</select>
我收到以下错误。
Error: [$compile:ctreq] Controller 'ngModel', required by directive 'ngChange', can't be found!
所有其他角度指令似乎都运行正常。我做错了什么?
答案 0 :(得分:4)
您需要为选择
设置ng-modelfor _, file := range files {
fmt.Println(file.Mode())
}
答案 1 :(得分:0)
ng-change reuires ng-model所以使用ng-model和ng-change
<select id = "email_templates" ng-model="selected" name =
"email_templates" class="chosen-select input-md form-control" ng-
change = "alert('template selected');">
<option value="0">No template selected</option>
<option value="1">Template 1</option>
</select>
答案 2 :(得分:0)
ngChange
表达式仅在输入发生变化时进行评估 value会将新值提交给模型。...
请注意,此指令要求
ngModel
存在。
ng-change
为您的模型变量创建观察者。因此,您必须在选择中添加ng-model
,以告知Angular您观察到的变量发生了变化。
<select ng-model="selectedEmail" ng-change="alert('template selected');">
答案 3 :(得分:0)
<select id = "email_templates" name = "email_templates" class="chosen-select input-md form-control" ng-change = "alert('template selected');">
<option value="0">No template selected</option>
<option value="1">Template 1</option>
</select>
而不是这个你可以使用ngClick选项。根据这个问题Responding to drop down selection change in angular without model binding
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
<select id = "email_templates" name = "email_templates" class="chosen-select input-md form-control" >
<option value="0">No template selected</option>
<option value="1" ng-click="alert('template selected');">Template 1</option>
</select>