【问题标题】:model of angular select not updating in controller角度选择模型未在控制器中更新
【发布时间】:2016-08-18 11:48:23
【问题描述】:

我试图在控制器中获取 $scope.selectedBranch 但它没有更新。如果我在 HTML 中使用 $scope.selectedBranch 它工作正常。

<select ng-model="selectedBranch" ng-change="onBranchChange()"  ng-options="branch for  branch in data.branches"

全部

$scope.onBranchChange= function(){
    console.log($scope.selectedBranch)  
};


data = {"branches" : ["343dfds","dfdf43","sdfsd","sadser343"]}

【问题讨论】:

    标签: angularjs select ng-options


    【解决方案1】:

    在 $scope 前加上数据。 应该是这样的:

    $scope.data = {"branches" : ["343dfds","dfdf43","sdfsd","sadser343"]}
    

    【讨论】:

    • 谢谢阿米特....但这不是问题...我只是忘记在此处的数据之前添加$scope....在实际代码中它仅$scope.data。
    • 然后代码在我的机器上运行良好。你可以创建或 plunkr 或类似的东西吗?
    猜你喜欢
    • 2013-07-28
    • 1970-01-01
    • 2017-08-28
    • 2017-02-17
    • 2015-09-01
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 2016-02-25
    相关资源
    最近更新 更多