AngularJS内部函数的值在函数外部为未定义。
创始人
2024-10-27 10:30:37
0

这个问题通常可以通过将值分配给作用域对象来解决。例如,如果您有一个控制器,您可以将它的值分配给 $scope 对象:

app.controller('MyController', function($scope) {
  $scope.myValue = 'Hello World';
});

现在,您可以在控制器内部和外部访问 $scope.myValue。如果您在控制器外部访问它,在前面加上 $scope 限定符:

app.controller('MyController', function($scope) {
  $scope.myValue = 'Hello World';
});

// ...

angular.element(document).ready(function() {
  var controllerElement = document.getElementById('my-controller');
  var controllerScope = angular.element(controllerElement).scope();
  console.log(controllerScope.myValue); // "Hello World"
});

相关内容

热门资讯

透视辅助!aapoker真的假... 透视辅助!aapoker真的假的(透视)插件(本来是有挂);1、不需要AI权限,帮助你快速的进行aa...
透视透视!aapoker怎么开... 透视透视!aapoker怎么开辅助器(透视)免费透视脚本(果然真的有挂);1、任何aapoker怎么...
透视肯定!aapoker破解侠... 透视肯定!aapoker破解侠是真的吗(透视)透视软件(总是真的有挂);1、上手简单,内置详细流程视...
透视插件!aapoker透视方... 透视插件!aapoker透视方法(透视)透视脚本下载(原来真的有挂)1)aapoker透视方法辅助挂...
透视代打!aapoker万能辅... 透视代打!aapoker万能辅助器(透视)万能辅助器(切实存在有挂)1、玩家可以在aapoker万能...
透视挂透视!aapoker脚本... 透视挂透视!aapoker脚本怎么用(透视)辅助(原来真的是有挂);1、下载好aapoker脚本怎么...
透视辅助!aapoker怎么设... 透视辅助!aapoker怎么设置抽水(透视)透视方法(真是真的有挂)1、进入游戏-大厅左侧-新手福利...
透视实锤!aapoker辅助器... 透视实锤!aapoker辅助器怎么用(透视)插件下载(总是真的有挂)1、完成aapoker辅助器怎么...
透视规律!aa poker透视... 透视规律!aa poker透视软件(透视)透视脚本下载(本来是真的有挂)运aa poker透视软件辅...
透视透视!aapoker辅助插... 透视透视!aapoker辅助插件工具(透视)透视方法(原来真的有挂)1、aapoker辅助插件工具a...