angularjs 1.5 组件依赖注入 [英] angularjs 1.5 component dependency injection

查看:31
本文介绍了angularjs 1.5 组件依赖注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能听起来很新,但我一直在关注这个教程 用于 angularjs 组件.

this may sound newb, but I have been following this tutorial for angularjs component.

我是组件的新手,如何像这样将常量 UtilsauthService 注入到我的组件中?

I am new to components and how do I inject a constant Utils or authService to my component like this?

app.component('tlOverallHeader', {
    bindings: {
        data: '='
    },
    templateUrl: 'js/indexTimeline/components/tl_overallHeader/templates/tl_overallHeader.html',
    controller: function() {
        this.ms = 'tlOverallheader!'
    }
})

谢谢!

推荐答案

您应该能够像独立控制器一样将服务注入到组件的控制器中:

You should be able to inject services into your component's controller just like a standalone controller:

controller: function(Utils, authService) {
    this.ms = 'tlOverallheader!'

    authService.doAuthRelatedActivities().then(...);
}

这篇关于angularjs 1.5 组件依赖注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆