在AngularJs中查找元素并更改其内容
Find element and change its content in AngularJs
我想更改标题div:的默认内容
<div>
<div>
<div class="page-header">
<h1><span>{{messages['default_title']}}</span></h1>
</div>
<div>
<!-- other elements-->
<div>
在我的控制器中,我写道:
var titleElement = angular.element('div.page-header');
titleElement.html('<h1><span>Hello</span></h1>');
div的内容更改成功:
<div class="page-header"><h1><span>Hello</span></h1></div>
但我收到了这个错误,页面无法成功加载:
TypeError: Cannot read property 'childNodes' of undefined
at g (https://localhost/test/js/angular/angular.min.js:47:278)
at g (https://localhost/test/js/angular/angular.min.js:47:273)
at g (https://localhost/test/js/angular/angular.min.js:47:273)
at g (https://localhost/test/js/angular/angular.min.js:47:273)
at g (https://localhost/test/js/angular/angular.min.js:47:273)
at https://localhost/test/js/angular/angular.min.js:46:377
at link (https://localhost/test/js/angular/angular-route.js:915:7)
at J (https://localhost/test/js/angular/angular.min.js:54:373)
at g (https://localhost/test/js/angular/angular.min.js:47:256)
at https://localhost/test/js/angular/angular.min.js:46:377 <div ng-view="" class="ng-scope">
而不是操纵页眉。
尝试更新控制器中的变量
$scope.messages['default_title'] = "Hello";
angular.element
接受HTML字符串或JS元素,而不是选择器
var titleElement = angular.element(document.querySelector('.page-header'));
titleElement.html('<h1><span>Hello</span></h1>');
相关文章:
- 在AngularJs中查找元素并更改其内容
- AngularJs-在两个数组中查找关系信息
- 通过匹配 - Javascript/AngularJS 中的参数来查找对象
- Angularjs元素在一个调用中同时查找select和input-这是单个标记查找的极限
- ReferenceError:Can't在AngularJS中查找变量:xxxService,Karma
- 如何通过指令在AngularJS中查找索引
- AngularJS与角度谷歌地图:添加标记通过fomr和查找我
- 在 AngularJS 中查找最接近的元素
- 查找对象数组(Angularjs)中是否存在值
- 如何通过使用 js 函数或可能是 angularjs 在新窗口中查找行的内容来直接滚动到表行
- AngularJS在第一个数组中查找对象,该对象未在第二个数组中呈现
- net::ERR_EMPTY_RESPONSE 当尝试在 AngularJS 指令中查找 CSS 文件时
- AngularJS 常规查找
- 在内部数组中查找项目 - angularJS
- 在 angularJS 中查找特定的元素标签
- 在文本输入中查找链接,并在 angularjs 中将它们转换为 html 链接
- 如何在 ng-click 上为 AngularJS 添加类以查找多个元素(巧妙地)
- “间歇”;jqLite不支持通过选择器查找元素"当使用RequireJS加载AngularJS时
- 查找一个项目是否在数组中,并使用angularjs将其从选择选项中排除
- AngularJS具有列定义查找的动态表