Make a dynamic function on ng-click

后端 未结 3 1484
臣服心动
臣服心动 2021-01-02 04:39

I have button like this


3条回答
  •  再見小時候
    2021-01-02 05:06

    This didn't work for me.. and..

    I didn't want to deal with having html code in my angular app, or directives, or the use of eval. so I just wrapped my existing functions in a function:

    $scope.get_results = function(){
    
        return {
                message: "A message", 
                choice1: {message:"choice 1 message", f: function(){$scope.alreadyDefinedFunction1()}},
                choice2: {message:"choice 2 message", f: function(){$scope.alreadyDefinedFunction2()}},
            };
    }
    

    in a different function:

    $scope.results2 = $scope.get_results();
    

    Snippet of use in html:

    
    

    Was based on this js fiddle: http://jsfiddle.net/cdaringe/FNky4/1/

提交回复
热议问题