Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.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
Javascript HTML中的范围变量未获取其值_Javascript_Angularjs - Fatal编程技术网

Javascript HTML中的范围变量未获取其值

Javascript HTML中的范围变量未获取其值,javascript,angularjs,Javascript,Angularjs,不要担心gallery.photos和photo指令。我的问题是,当加载DOM而不是0时,计数器没有值为什么?和如何修复它以使其从控制器读取值?控制器中的$scope在哪里?您需要在控制器中添加$scope.counter=0而不是此,任何附加到$scope的内容都可以从视图中读取。控制器中的$scope在哪里?您需要在控制器中添加$scope.counter=0,而不是此,任何附加到$scope的内容都可以从视图中读取。您可以使用 (function() { angular .mo

不要担心
gallery.photos和photo指令
。我的问题是,当加载DOM而不是0时,计数器没有值为什么?和如何修复它以使其从控制器读取值?

控制器中的$scope在哪里?您需要在控制器中添加$scope.counter=0而不是,任何附加到$scope的内容都可以从视图中读取。

控制器中的$scope在哪里?您需要在控制器中添加$scope.counter=0,而不是,任何附加到$scope的内容都可以从视图中读取。

您可以使用

(function() {
  angular
    .module('myapp')  
    .controller('GalleryController', GalleryController);

  GalleryController.$inject = ['GalleryService'];

  function GalleryController(GalleryService){
     var self=this;
     self.counter=0;
  } 
})();

你可以打电话给柜台

(function() {
  angular
    .module('myapp')  
    .controller('GalleryController', GalleryController);

  GalleryController.$inject = ['GalleryService'];

  function GalleryController(GalleryService){
     var self=this;
     self.counter=0;
  } 
})();

您必须以
库的形式访问它。计数器
,因为您没有将计数器添加到
$scope
,而是添加到控制器的
非常感谢您,您必须以
库的形式访问它。计数器
,因为您没有将计数器添加到
$scope
,但是对于管制员的
这个
非常感谢你,伙计
 gallery.counter