在控制器中定义的HTML中调用函数

时间:2015-05-14 16:56:19

标签: javascript html angularjs

如何在加载HTML页面时调用函数?现在,通过按下按钮手动进行函数调用,如:

def question_correct?(cucumber_table, question, answer)
  hash = cucumber_table.rows_hash
  return false if hash[question].nil?
  return hash[question] == answer
end

也可以使用{{getAddress()}}调用函数。但是,正如预期的那样,它会导致无限循环。

getAddress()调用后端,获取数据并填充$ scope($ scope.address)上的地址

自动加载它并摆脱按钮会很好。

1 个答案:

答案 0 :(得分:2)

在控制器本身中,您可以调用getAddress()。 您可能拥有如下控制器

myapp.controller('yourController', function($scope){
        $scope.address = "";
        $scope.getAddress = function(){
           $scope.address = "some address"; 
        };
        //You can call here itself, it will get invoked when page and in  turn your script loads
        $scope.getAddress();
});