首页 > 解决方案 > ng-click 在按钮上不起作用(angularjs-django)

问题描述

我是 angularjs 的新手,无法弄清楚为什么 ng-click on a button 不起作用。我在下面粘贴代码。我正在使用 django 服务器来呈现页面。

HTML 代码:

<body ng-controller="myController">

<div class="container-fluid" >
    <table class="col-xs-12-ls-12 mfPortfolioTable" width="100%">
        <tbody>
            <tr ng-repeat="x in records">
                <td class="search_table_cell col-xs-1-ls-1">{% verbatim %}{{ x.units | number:3 }}{% endverbatim %}</td>
            </tr>
            <tr>                
                <td><button class="btn btn-primary" ng-click="updateMfPortfolio()" id="updateFolio">Update</button></td>
            </tr>
        </tbody>
    </table>
</div>
</body>

控制器代码:

var app = angular.module('searchApp', []);
app.controller('myController', function($scope, $http) {
  $http.get('/somelink/').then(function(response){
      $scope.records = response.data.data;
  });

  //This is the function which I expect to get triggered by ng-click

  $scope.updateMfPortfolio = function(){
      console.log('Updating MF Portfolio...');
      $http.get('/somelink/').then(function(response){
          console.log('Code reached here...');
          $scope.records = response.data.data;
      });
  };

标签: angularjsdjango

解决方案


推荐阅读