我无法选择有角度的元素。我必须犯一些愚蠢的错误:
function Root($scope) { $scope.elem = angular.element('div'); }
造成的错误:
Error: selectors not implemented at Error (<anonymous>) at Object.JQLite [as element] (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:1523:13) at new Root (http://fiddle.jshell.net/kzX9z/7/show/:28:27) at invoke (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:2795:28) at Object.instantiate (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:2805:23) at $get (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:4621:24) at $get.i (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:4200:17) at forEach (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:117:20) at nodeLinkFn (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:4185:11) at compositeLinkFn (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:3834:14) angular.js:5563 $get angular.js:5563 $get angular.js:4661 $get.Scope.$apply angular.js:7890 SNAKE_CASE_REGEXP angular.js:930 invoke angular.js:2788 bootstrap angular.js:928 angularInit angular.js:904 (anonymous function) angular.js:14397 trigger angular.js:1695 event.preventDefault angular.js:1930 forEach angular.js:110 eventHandler
我究竟做错了什么?我包括jQuery。这不是应该工作吗?
这是因为需要在角度之前引用jquery。 JSFiddle注册了Angular 1.0.2 FIRST,然后添加了jquery verson作为资源。
原文链接:/angularjs/145079.html<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script>
这样Angular知道它可以使用JQuery而不是JQLite。一旦你这样做,选择器将工作在angular.element()
@L_502_1@
如果没有JQuery,可以手动选择DOM元素。
var div = document.querySelector('div'); $scope.elem = angular.element(div);