Angularjs 如何在控制器中编写返回某些值或对象的函数?
如何在控制器中编写返回某个值或对象的函数? 像Angularjs 如何在控制器中编写返回某些值或对象的函数?,angularjs,Angularjs,如何在控制器中编写返回某个值或对象的函数? 像 如何实现它?您可以在控制器中编写一个函数。例如: myApp.controller('thisController', function($scope){ $scope.thisValue = false; function myFunction(){ console.log('from this function'); return true; } $scope.thisValue = myFunction();
如何实现它?您可以在控制器中编写一个函数。例如:
myApp.controller('thisController', function($scope){
$scope.thisValue = false;
function myFunction(){
console.log('from this function');
return true;
}
$scope.thisValue = myFunction();
});
确保不要忘记函数调用末尾的“;”符号。其余的我觉得还可以。注意,您必须声明对象$scope并确保它不是空的 有关控制器的详细信息,请阅读:
你提供的例子有什么问题吗?给我一个空白的背景它对我有用。。。编一把小提琴。。
myApp.controller('thisController', function($scope){
$scope.thisValue = false;
function myFunction(){
console.log('from this function');
return true;
}
$scope.thisValue = myFunction();
});
$scope.someOtherFunc(){
var numbers={};
numbers=$scope.getTwoNumber();
}