当我使用 angularjs 和温泉 ui 开发我的混合应用程序时,有一个关于错误的错误;[jqLite:nosel]
When I develop my hybird app using angularjs and onsen ui ,there is a bug about Error;[jqLite:nosel]
我想定义一个指令,代码如下:
var module = ons.bootstrap('my-app', ['onsen','ngSanitize']);
module.directive("dyCompile", ["$compile", function($compile) {
return {
restrict: 'EA',
link: function(scope, elm, iAttrs) {
var DUMMY_SCOPE = {
$destroy: angular.noop
},
root = elm,
childScope,
destroyChildScope = function() {
(childScope || DUMMY_SCOPE).$destroy();
};
iAttrs.$observe("html", function(html) {
destroyChildScope();
childScope = scope.$new(false);
var content = $compile(html)(childScope);
root.replaceWith(content);
root = content;
scope.$on("$destroy", destroyChildScope);
});
}
};
}])
而HTML是这样的:
<div class="arInfo">
<dy-compile html="bodyText">
</dy-compile>
</div>
头部是:
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<script src="components/loader.js"></script>
<script src="./js/jquery-2.1.4.js"></script>
<script src="./js/angular-sanitize.js"></script>
<script src="./js/winstore-jscompat.js"></script>
<script src="./js/script.js"></script>
<script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/angular-loading-bar/0.7.1/loading-bar.min.js'></script>
<link rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/angular-loading-bar/0.7.1/loading-bar.min.css' type='text/css' media='all' />
<link rel="stylesheet" href="components/loader.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesshet" href="components/monaca-onsenui/js/angular/angular-csp.css">
但是当我 运行 我的应用程序时,出现错误:
“错误:[jqLite:nosel] jqLite 不支持通过选择器查找元素!参见:http://docs.angularjs.org/api/angular.element
“
我想可能是加载angularjs和jquery的顺序不对,但是如你所见,我先加载jquery,我真的不知道这是什么原因,有人可以帮我吗?
我没有看到您 'angular.js' 的负载。它是由 'components/loader.js' 脚本完成的吗?
在那种情况下,您在加载 jQuery 之前加载 'angular.js',这会导致 jqLite 错误。
将 jQuery 的负载置于 'components/loader.js'
的负载之上
我想定义一个指令,代码如下:
var module = ons.bootstrap('my-app', ['onsen','ngSanitize']);
module.directive("dyCompile", ["$compile", function($compile) {
return {
restrict: 'EA',
link: function(scope, elm, iAttrs) {
var DUMMY_SCOPE = {
$destroy: angular.noop
},
root = elm,
childScope,
destroyChildScope = function() {
(childScope || DUMMY_SCOPE).$destroy();
};
iAttrs.$observe("html", function(html) {
destroyChildScope();
childScope = scope.$new(false);
var content = $compile(html)(childScope);
root.replaceWith(content);
root = content;
scope.$on("$destroy", destroyChildScope);
});
}
};
}])
而HTML是这样的:
<div class="arInfo">
<dy-compile html="bodyText">
</dy-compile>
</div>
头部是:
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<script src="components/loader.js"></script>
<script src="./js/jquery-2.1.4.js"></script>
<script src="./js/angular-sanitize.js"></script>
<script src="./js/winstore-jscompat.js"></script>
<script src="./js/script.js"></script>
<script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/angular-loading-bar/0.7.1/loading-bar.min.js'></script>
<link rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/angular-loading-bar/0.7.1/loading-bar.min.css' type='text/css' media='all' />
<link rel="stylesheet" href="components/loader.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesshet" href="components/monaca-onsenui/js/angular/angular-csp.css">
但是当我 运行 我的应用程序时,出现错误: “错误:[jqLite:nosel] jqLite 不支持通过选择器查找元素!参见:http://docs.angularjs.org/api/angular.element “
我想可能是加载angularjs和jquery的顺序不对,但是如你所见,我先加载jquery,我真的不知道这是什么原因,有人可以帮我吗?
我没有看到您 'angular.js' 的负载。它是由 'components/loader.js' 脚本完成的吗?
在那种情况下,您在加载 jQuery 之前加载 'angular.js',这会导致 jqLite 错误。
将 jQuery 的负载置于 'components/loader.js'
的负载之上