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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.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,我正在尝试为从服务填充的下拉列表编写一个简单的指令: “--选择模型--” {{existingModel}} (函数(){ "严格使用",; var module=angular.module('components.widgets',['rest.services']); module.directive('modelnamelector',function($http、$rootScope、modelNames){ 返回{ 限制:'E', templateUrl:'app/compon

我正在尝试为从服务填充的下拉列表编写一个简单的指令:


“--选择模型--”
{{existingModel}}
(函数(){
"严格使用",;
var module=angular.module('components.widgets',['rest.services']);
module.directive('modelnamelector',function($http、$rootScope、modelNames){
返回{
限制:'E',
templateUrl:'app/components/model/model name selector.html',
控制器:函数($scope,modelNames){
var t=‘thing’
modelNames.getAll().$promise.then(函数(数据){
//为什么我看不见“t”???
//为什么我不能访问$scope?
});
$scope.changed=函数(){
//我在这里也看不到
}
}
}
});
})();

modelNames.getAll()
与资源对话,并返回正确的数据,但当它返回时,我需要做一些事情,无法访问回调闭包之外定义的范围或任何内容。在更改的回调中,我可以使用
this
访问范围,但在
getAll
的回调中,
this
是窗口。我真的很困惑。

如果您遇到断点,您将无法访问,但添加访问
t
$scope
的代码,变量将可用。您是对的。这让我难堪了好久!非常感谢!为什么会这样?为什么断点看不到变量?我认为这是一个优化,来自JS引擎。见例。