通过角类中的类获取元素

时间:2014-10-13 16:23:25

标签: angularjs

我需要找到类ngAggregate的第一个元素,带有角度

我想在角度中找到等效物:

document.getElementsByClassName('ngAggregate')[0]; (which works)

但是,我不能使用它,因为我需要稍后进行一些绑定。

我试过了:

var aggregate =  angular.element('.ngAggregate')[0];

但我很震惊地说,angular.element(' .ngAggregate')未定义。

正确的写作方法是什么?

更新:

var aggregate =  angular.element(document.getElementsByClassName('ngAggregate')[0]);

不会返回错误,但我希望得到"聚合"

console.log(aggregate.childNodes[1].innerHTML);

我得到了

 Cannot read property '1' of undefined

这是完整的错误:

TypeError: Cannot read property '1' of undefined
at HTMLDocument.<anonymous> (http://localhost:8000/src/search/searchCtrl.js:377:49)
at j (http://localhost:8000/components/jquery/jquery-1.11.0.min.js:2:27136)
at Object.k.add [as done] (http://localhost:8000/components/jquery/jquery-1.11.0.min.js:2:27445)
at n.fn.ready (http://localhost:8000/components/jquery/jquery-1.11.0.min.js:2:29551)
at new <anonymous> (http://localhost:8000/src/search/searchCtrl.js:370:35)
at invoke (http://localhost:8000/components/angular/angular.js:3720:17)
at Object.instantiate (http://localhost:8000/components/angular/angular.js:3731:23)
at http://localhost:8000/components/angular/angular.js:6848:28
at updateView (http://localhost:8000/components/angular-ui-router/angular-ui-router.js:2286:30)
at http://localhost:8000/components/angular-ui-router/angular-ui-router.js:2234:9 <div ui-view=""> 

0 个答案:

没有答案