我正在使用ng-options填充的选择框。不幸的是,我无法调用ng-change函数。

Here is my Fiddle

这是我的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;
}

这是我的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>

目前,这使我无法进行项目工作,因此,非常感谢您的帮助。谢谢!

最佳答案

2件事...都很简单:)

  • ng-change=onSelectChange应该是onSelectChange()
  • this.message应该是this.scopeMessage
  • 关于javascript - ng-change不适用于ng-select,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25370555/

    10-09 19:33