Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何在控制器中编写返回某些值或对象的函数?_Angularjs - Fatal编程技术网

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();
}