简体   繁体   English

打字稿导入模块(ngCookies)

[英]Typescript importing Modules (ngCookies)

I have downloaded a sample of an admin dashboard in Typescript/Angular. 我已经在Typescript / Angular中下载了一个管理仪表盘的示例。 It's built up in a very modular way with .component, .routing, .module files. 它使用.component,.routing和.module文件以非常模块化的方式构建。

Now I need to import the cookie module. 现在,我需要导入cookie模块。 I was used to import modules by injecting them into a Component constructor from what I've read, but the Angular documentation says that I need to use the 我习惯于通过将模块从我已阅读的内容注入到Component构造函数中来导入模块,但是Angular文档说我需要使用

angular.module('app', ['ngCookies']);

directive to import it. 指令导入。

So I tried it but it gives me an error (cannot find 'angular'). 所以我尝试了一下,但是它给了我一个错误(找不到“角度”)。 I think the problem might be that its meant for javascript. 我认为问题可能在于它的意思是javascript。

Can anyone help me with a minimal example of importing cookies in typescript? 有人可以在打字稿中导入Cookie的最小示例帮助我吗?

These comments set me on the right track. 这些评论使我走上了正确的道路。 If anyone struggles with this, 如果有人为此苦苦挣扎,

use 采用

import { CookieService } from 'ng2-cookies';

then in the Component 然后在组件中

@Component{(
    providers: [ CookieService ]
})

now it works with constructor injection 现在可以与构造函数注入一起使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM