1

In my code there is:

<button class="btn float-right" data-ng-click="test()">
    Reset
</button>

Is it possible for me to fire more than one function when I do a click of the button. If so how should I code that?

Update. I would like to call the test() function in the current scope and the otherTest() function in the parent scope / controller.

4

2 回答 2

3

您应该修改您的test函数以包含更多逻辑:

$scope.test = function(){
    test1();
    test2();
    //...
    testN();
} 
于 2013-07-07T09:32:26.847 回答
1

我想调用当前作用域中的 test() 函数和父作用域/控制器中的 otherTest() 函数。

只需ortherTest在您的父范围内定义您的。例如:

function ParentController($scope){
     $scope.otherTest = function(){

     }
}

有两种方法可以实现您想要的:您可以尝试:

function CurrentController($scope){
     $scope.test = function(){

     }
}

data-ng-click="test();otherTest()"

或者:

function CurrentController($scope){
     $scope.test = function(){
          $scope.otherTest();
          //Your test code for this function
     }
}

data-ng-click="test()"

由于范围是继承的,您当前的范围将从otherTest父范围继承

于 2013-07-07T09:49:44.110 回答