Javascript Angularjs:ng选择列表的更改
我使用的是angularjs,我有一个指示,显示问题列表。当Javascript Angularjs:ng选择列表的更改,javascript,angularjs,angularjs-directive,Javascript,Angularjs,Angularjs Directive,我使用的是angularjs,我有一个指示,显示问题列表。当selectedQuestion更改时,我打算执行一些逻辑。因此,我使用了ng change 这是我的指示: restrict: 'EA', scope: { selectedQuestion: '=?', questionsList: '=' },
selectedQuestion
更改时,我打算执行一些逻辑。因此,我使用了ng change
这是我的指示:
restrict: 'EA',
scope: {
selectedQuestion: '=?',
questionsList: '='
},
link: function (scope) {
scope.change = function () {
if (scope.selectedQuestion) {
//do something
}
};
}
<select ng-model="selectedQuestion"
ng-options="avail.question for avail in questionsList track by avail.id" ng-change="change()"
</select>
{{selectedQuestion}}
link: function (scope) {
scope.change = function (currentQuestion) {
if (currentQuestion) {
}
};
}
这是my指令的html模板:
restrict: 'EA',
scope: {
selectedQuestion: '=?',
questionsList: '='
},
link: function (scope) {
scope.change = function () {
if (scope.selectedQuestion) {
//do something
}
};
}
<select ng-model="selectedQuestion"
ng-options="avail.question for avail in questionsList track by avail.id" ng-change="change()"
</select>
{{selectedQuestion}}
link: function (scope) {
scope.change = function (currentQuestion) {
if (currentQuestion) {
}
};
}
尝试将模型作为参数传递给ng change
函数:
<select ng-model="selectedQuestion"
ng-options="avail.question for avail in questionsList track by avail.id"
ng-change="change(selectedQuestion)"
</select>
尝试将模型作为参数传递给ng change
函数:
<select ng-model="selectedQuestion"
ng-options="avail.question for avail in questionsList track by avail.id"
ng-change="change(selectedQuestion)"
</select>