Javascript 元素(';#someId';).scope()在IE 9中返回未定义

Javascript 元素(';#someId';).scope()在IE 9中返回未定义,javascript,jquery,angularjs,internet-explorer-9,Javascript,Jquery,Angularjs,Internet Explorer 9,我使用的是angular.js 1.2.13。我使用的是第三方工具,它使用angular.js,为了在我的项目中集成,我在.js文件中使用angular.js代码 为了获取范围数据,我在HTML元素上使用.scope()。它在chrome和mozilla中运行良好,但在IE 9上,angular.element(“#someId”).scope()返回未定义 我已经调试并发现angular.element(“#someId”)返回的是预期的元素,但是.scope()返回的是未定义的元素 在ang

我使用的是angular.js 1.2.13。我使用的是第三方工具,它使用angular.js,为了在我的项目中集成,我在.js文件中使用angular.js代码

为了获取范围数据,我在HTML元素上使用.scope()。它在chrome和mozilla中运行良好,但在IE 9上,angular.element(“#someId”).scope()返回未定义

我已经调试并发现angular.element(“#someId”)返回的是预期的元素,但是.scope()返回的是未定义的元素

在angular.js的网站上,有人写道1.2.X与IE9完全兼容。为什么我会犯这个错误

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>


//This code is written in external js file appConfig.js which is imported after angular.js
angular.module('modelerApp', []).run(['$rootScope', function($rootScope){

    //This function is defined by me
    $rootScope.bootstrap = function() {
        //some logic needs to be executed here which should happen only after page load, so I am keeping it inside rootscope
    }

}]);


<script type="text/javascript">
//This code is written in external js file which is getting imported in this page
  $(document).ready(function(){

    var scope = angular.element('#someId').scope(); //undefined

    //I need scope to access rootscope of angular in order to execute logic inside bootstrap method
    var rootScope = scope.$root; 

    //I want to execute logic written in bootstrap method, which is in $rootScope
    //This logic uses angular js routes and all, and thus needs to be inside angular code.
    //This has nothing to do with specific controller
    rootScope.bootstrap();

  });

</script>

<div ng-app="modelerApp" ng-controller="itemController">
  <div id="main">
    <div id="someId">
    </div>
  </div>
</div>

//此代码编写在外部js文件appConfig.js中,该文件在angular.js之后导入
angular.module('modelerApp',[])。运行(['$rootScope',函数($rootScope){
//这个函数是由我定义的
$rootScope.bootstrap=function(){
//这里需要执行一些逻辑,这些逻辑应该只在页面加载之后执行,所以我将其保存在rootscope中
}
}]);
//此代码是在外部js文件中编写的,该文件将被导入此页面
$(文档).ready(函数(){
var scope=angular.element('#someId').scope();//未定义
//我需要作用域来访问angular的根作用域,以便在引导方法中执行逻辑
var rootScope=scope.$root;
//我想执行用bootstrap方法编写的逻辑,它位于$rootScope中
//此逻辑使用angular js路由和所有路由,因此需要在angular代码中。
//这与特定控制器无关
bootstrap();
});

非常感谢您的帮助。

如果您试图访问angular范围之外的范围,并且您不在angular的路径上,您不应该以这种方式将angular与jQuery一起使用,而是将jQuery包含在angular之上,以利用jQuery而不是angular的jqLite:

angular.module('modelerApp',[]).controller('itemController',function($scope){
var scope=angular.element($('#someId')).scope();//未定义
$scope.obj={
scopeId:scope.$id
};
//console.log(范围$id);
});

{{obj.scopeId}

如果您试图访问angular范围之外的范围,并且您不在angular的路径上,您不应该以这种方式将angular与jQuery一起使用,而是将jQuery包含在angular之上,以利用jQuery而不是angular的jqLite:

angular.module('modelerApp',[]).controller('itemController',function($scope){
var scope=angular.element($('#someId')).scope();//未定义
$scope.obj={
scopeId:scope.$id
};
//console.log(范围$id);
});

{{obj.scopeId}

其他浏览器呢?在那些浏览器中它也没有定义吗?它在其他浏览器(chrome和mozilla firefox)中工作。其他浏览器呢?它在那些浏览器中也没有定义吗?它在其他浏览器(chrome和mozilla firefox)中工作,实际上我已经导入了jQuery。这里的特殊情况是,我必须执行一些逻辑,但只能在page ready事件上执行。代码使用角度路由和其他特性,因此我在一个函数中提取了这些特性,并将其保存在run函数中的rootScope中。为了访问rootscope,我使用的是在IE9中返回为未定义的范围。为了更好的理解,你们可以参考我编辑过的问题。实际上我已经导入了jQuery。这里的特殊情况是,我必须执行一些逻辑,但只能在page ready事件上执行。代码使用角度路由和其他特性,因此我在一个函数中提取了这些特性,并将其保存在run函数中的rootScope中。为了访问rootscope,我使用的是在IE9中返回为未定义的范围。要了解更多信息,请参考我编辑的问题。