我正在努力加快1.5角度组件的速度.我一直在追踪道格的视频,以便在零件上开始使用角度的文档
https://docs.angularjs.org/guide/component.
在这一点上,组件正在取代使用控制器的指令,但是在我们的1.5代码中,我们仍然会使用指令进行dom操作.
组件控制器内的$element,$attrs的用途是什么?这些似乎可用于操纵.这是链接到文档的plunker.我知道他们没有使用$元素,但这是我正在阅读的例子. http://plnkr.co/edit/Ycjh1mb2IUuUAK4arUxe?p=preview
但在代码如此…
- angular
- .module('app',[])
- .component('parentComponent',{
- transclude: true,template: `
- <div ng-transclude></div>
- `,controller: function () {
- this.foo = function () {
- return 'Foo from parent!';
- };
- this.statement = function() {
- return "Little comes from this code";
- }
- }
- })
- .component('childComponent',{
- require: {
- parent: '^parentComponent'
- },controller: function () {
- this.$onInit = function () {
- this.state = this.parent.foo();
- this.notice = this.parent.statement();
- };
- },template: `
- <div>
- Component! {{ $ctrl.state }}
- More component {{$ctrl.notice}}
- </div>
- `
- })
如果我们不操纵dom,将使用$element?