【问题标题】:Passing Parameter back to Component [duplicate]将参数传递回组件[重复]
【发布时间】:2018-08-28 05:33:37
【问题描述】:

以下代码让我度过了最糟糕的时光:

angular.
    module('albumCarousel').
    component('albumCarousel', {
        templateUrl: '/album-carousel/album-carousel.template.html',

        controller: function AlbumCarouselController($scope, $http) {
            /* the bane of my existence */
            console.log(this.category); // prints undefined..
        }
    }
)

在我的 html 中,我有以下内容:

<angular-carousel category="songs"></angular-carousel>

回到组件,在控制器中,

this.category comes back as undefined.

如何让它返回“歌曲”

【问题讨论】:

标签: angularjs


【解决方案1】:

经过一番谷歌搜索,我找到了答案:$onInit:

this.$onInit=function() {
    console.log(this.category)
}

我还必须添加一个绑定:

    bindings: {
        category: '@',
    }

感谢大家的帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-18
    • 1970-01-01
    • 1970-01-01
    • 2019-12-26
    • 2012-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多