pokeApp.controller('mycontroller', function($scope, $routeParams){
// part 1: // why would this not work
$scope.myFunc();
$scope.myFunc = function(){
console.log("Hi !");
}
// part 2: // why would this not work
this.helloWorld();
this.helloWorld = function(){
console.log("Hello World");
}
}
嗨 我的问题是为什么这两件事不起作用;我的意思是要么在 Controller 中,要么在范围内。我知道我可以调用一个简单定义的函数 'function helloWorld(){...}'
谢谢!
最佳答案
您在定义函数之前调用该函数。将代码更改为:
$scope.myFunc = function(){
console.log("Hi !");
}
$scope.myFunc();
关于javascript - angularjs 从 Controller 内部调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27596088/