生命周期钩子this.$postLink出现类型错误

3
我正在尝试学习angular 1.5组件,并遇到了问题。以下代码是我的组件启动布局,使用gruntjob编译时没有错误。
angular.module('layout',[]).component('kiHeaderParallax',{
        controller: myController,
        controllerAs: 'comp',
        template:'<div>Yo</div>'
    });

    function myController(){
        this.$postLink(domManipulation);
        console.log('poop');
    }

    function domManipulation(){
        console.log('poop2');
    }


angular.element(document).ready(function() {
      angular.bootstrap(document, ['layout']);
    });

然而,当我打开浏览器时,出现了类型错误:
> 1.angular-1.5.5.js:13550TypeError: this.$postLink is not a function
>     at new myController (ki-header-parallax.component.ts:14)
>     at Object.invoke (1.angular-1.5.5.js:4665)
>     at $controllerInit (1.angular-1.5.5.js:10115)
>     at nodeLinkFn (1.angular-1.5.5.js:9033)
>     at compositeLinkFn (1.angular-1.5.5.js:8397)
>     at compositeLinkFn (1.angular-1.5.5.js:8400)
>     at compositeLinkFn (1.angular-1.5.5.js:8400)
>     at publicLinkFn (1.angular-1.5.5.js:8277)
>     at hint.js:1480
>     at 1.angular-1.5.5.js:1751

我正在使用Angular 1.5.5 - 因此这不应该是问题 - 为什么我无法得到我的日志?

Codepen链接:http://codepen.io/anon/pen/JXQXgN?editors=1010

1个回答

2
解决方案
this.$postLink = domManipulation;

替换为
this.$postLink(domManipulation);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接