【问题标题】:Lifecycle hook this.$postLink gives typeerror生命周期挂钩 this.$postLink 给出类型错误
【发布时间】:2016-09-16 02:38:57
【问题描述】:

我正在尝试学习 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']);
    });

但是当我进入浏览器时,我得到了这个 typeError:

> 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

【问题讨论】:

    标签: angularjs angularjs-components angularjs-lifecycle


    【解决方案1】:

    解决办法

    this.$postLink = domManipulation;
    

    而不是

    this.$postLink(domManipulation);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-02
      • 2019-10-01
      • 2017-06-07
      • 1970-01-01
      • 1970-01-01
      • 2017-01-18
      • 1970-01-01
      相关资源
      最近更新 更多