AngularJS将函数添加到作用域

AngularJS add function to scope

本文关键字:作用域 添加 函数 AngularJS      更新时间:2024-01-11

嗨,我有个烦人的问题。我正在尝试向$scope添加两个方法。我这样做是对的:

function typeCtrl ($scope, $timeout) {    
  $scope.addType = function(){
      requestHelper.addType();
  };
  $scope.removeType = function(number){
      alert("asdasdsad");
      requestHelper.removeType(number);
  };
 };

我试着这样称呼它:

<button id="addType" class="btn btn-primary glyphicon glyphicon-plus" ng-click="addType()"></button>
<button id="removeRequest" class="btn btn-danger glyphicon glyphicon-minus" ng-click="removeType(1)"></button>

方法addType()工作正常,但角度不正确。请参阅removeType()方法。你能告诉我我做错了什么吗。谢谢回复。

这会是因为第一个按钮上没有括号吗?