且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我怎样才能访问"本"在我的控制器使用&QUOT时,控制器为"句法?

更新时间:2022-06-22 01:43:03

您需要保持这一基准的功能的启动和使用。 这个我相信在您的函数是全局窗口的情况下。这一切都取决于函数是如何调用,并且它在哪里定义。

You need to keep the reference of this at the start of the function and use that. The context of this i believe in your function is the global window. It all depends upon how the function is invoked and where is it defined.

app.controller('ChildCtrl', function($scope) {
  var self=this;
  $scope.name1 = 'Child';
  this.name1 = 'Child';
  this.option = {};
  this.option.abc = 25;

  foo = function(){
    alert(self.option)
  };

  foo();
});