【问题标题】:@scope value attached to button control not updating? MVC AngularJs附加到按钮控件的@scope 值未更新? MVC AngularJs
【发布时间】:2019-06-18 12:35:00
【问题描述】:

我有 $scope.buttonId = 0 的默认值

我在按钮 ng-click 中使用的功能类似,

<button type="button" class="btn green" ng-click="vm.Update({{buttonId}})">
    {{ 'Save' | translate }}
</button>

这里它在按钮功能中显示0。但是当我在控制器函数中更改$scope.buttonId 值时,

vm.Select = function (value) {
    $scope.buttonId = 5;
}

它没有更新$scope 值。它在使用 for view 的同一个控制器中。

有没有其他方法可以将 id 传递给按钮功能。

希望您的建议

谢谢

【问题讨论】:

    标签: angularjs asp.net-mvc model-view-controller angularjs-directive angularjs-scope


    【解决方案1】:

    您不需要在ng-Click 指令中使用{{buttonId}} 插值绑定。只需使用buttonId 即可。

    <button type="button" class="btn green" ng-click="vm.Update(buttonId)" >{{ 'Save' | translate }}</button>
    

    查看此示例以进行演示。

    <!DOCTYPE html>
    <html>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
    <body>
    
    <div ng-app="myApp" ng-controller="customersCtrl">
     
    <p>Input something in the input box:</p>
    <p>Name : <input type="text" ng-model="name" placeholder="Enter name here"></p>
    <h1>{{name}}</h1>
    <input type="button" ng-Click="view(name)" value="View"/>
    </div>
    <script>
    var app = angular.module('myApp', []);
    app.controller('customersCtrl', function($scope, $http) {
     $scope.view=function(value)
     {
     	alert(value);
     }
    });
    </script></body>
    </html>

    希望它能解决您的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多