本文介绍了不工作的NG-变化NG-选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是由 NG选项填充一个选择框。不幸的是,我不能让我的 NG-变化函数来调用。

I'm using a select box that is populated by the ng-options. Unfortunately, I cannot get my ng-change function to call.

下面是我的 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>

这是目前持有我在我的项目工作,所以任何帮助将是geatly AP preciated。谢谢!

This is currently holding me up on my project for work, so any help will be geatly appreciated. Thanks!

推荐答案

2的事情......既简单:)

2 things... both simple :)


  1. NG-变化= onSelectChange onSelectChange()

  2. this.message this.scopeMessage

  1. ng-change=onSelectChange should be onSelectChange()
  2. this.message should be this.scopeMessage

这篇关于不工作的NG-变化NG-选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 18:07