【发布时间】:2018-08-06 21:10:16
【问题描述】:
我已运行命令“npm install --save ng2-social-share”。
然后添加到 app.module.ts 中:-
import { CeiboShare } from 'ng2-social-share';
@NgModule({
imports: [
CeiboShare
]
});
然后我添加到我的 home.component.ts 中:-
import { CeiboShare } from 'ng2-social-share';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css'],
directives: [CeiboShare]
})
webpack:正在编译... src/app/home/home.component.ts(16,3) 中的错误:错误 TS2345:类型参数 '{ 选择器:字符串;模板网址:字符串; styleUrls: 字符串[];指令:typeof CeiboShare[]; }' 不可分配给“组件”类型的参数。 对象字面量只能指定已知属性,而“组件”类型中不存在“指令”。
日期:2018-02-27T09:02:42.288Z - 哈希:bedb972b22f9a72ebb59 - 时间:2832ms 5个不变的块 chunk {main} main.bundle.js (main) 367 kB [initial] [rendered]
webpack:编译成功。
【问题讨论】:
-
你能分享一些代码吗?
-
你不需要在组件级别包含指令,你只需要在你的模块的导入部分中导入它
-
如果我删除指令。仍然感到困惑我下一步应该做什么来将社交分享整合到我的组件中