Web*_*rer 13 javascript angularjs
我正在使用填充的选择框ng-options.不幸的是,我无法ng-change调用我的函数.
这是我的js:
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.typeOptions = [
{ name: 'Feature', value: 'feature' },
{ name: 'Bug', value: 'bug' },
{ name: 'Enhancement', value: 'enhancement' }
];
$scope.scopeMessage = "default text";
var changeCount = 0;
$scope.onSelectChange = function()
{
changeCount++;
this.message = "Change detected: " + changeCount;
}.bind($scope);
//$scope.form = {type : $scope.typeOptions[0].value};
$scope.form = $scope.typeOptions[0].value;
}
Run Code Online (Sandbox Code Playgroud)
这是我的HTML:
<div ng-controller="MyCtrl" class="row">
<select ng-model='form' required ng-options='option.value as option.name for option in typeOptions' ng-change="onSelectChange"></select>
<div style="border:1px solid black; width: 100px; height:20px;">{{scopeMessage}}<div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是目前我的工作项目,所以任何帮助将得到热烈的赞赏.谢谢!
Tim*_*thy 16
2件事......既简单:)
ng-change=onSelectChange 应该 onSelectChange()this.message 应该 this.scopeMessage您的问题是您正在将函数引用传递给ng-change指令.但是,该指令需要一个可以计算的表达式.因此,将括号附加到函数中,以便可以将其作为函数调用进行求值.
喜欢这里:http://jsfiddle.net/MTfRD/1101/
<select ng-model='form' required ng-options='option.value as option.name for option in typeOptions' ng-change="onSelectChange()"></select>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
34636 次 |
| 最近记录: |