【问题标题】:Unexpected value 'CeiboShare' in Please add a @Pipe/@Directive/@Component annotation请添加@Pipe/@Directive/@Component 注释中的意外值“CeiboShare”
【发布时间】:2021-03-22 22:41:47
【问题描述】:

我正在使用 angular4,并且我使用 ng2-social-share 来使用社交分享按钮,它工作正常,但是当我发布我的项目时,它抛出了以下错误:-

错误值 'CeiboShare in E:/code/SportsFoundation/Gamification.Clients.Spa/node_modules/ng2-social-share/src/ng2-social-share.d.ts' 由模块 'AppModuleShared in 声明 E:/code/SportsFoundation/Gamification.Clients.Spa/ClientApp/app/app.module.shared.ts'。 请添加@Pipe/@Directive/@Component 注解。

我正在关注以下文章:- https://www.npmjs.com/package/ng2-social-share

在 Angular 4 中我们没有 [directive],所以我在 @ngModule 的声明部分使用它

【问题讨论】:

标签: angular


【解决方案1】:

是的,你是对的,问题在于包在构建 Angular 版本大于 2 的项目期间不受支持,因为指令不再是组件装饰器的一部分,即使你在模块声明中声明它,你的应用也支持在本地打包,但是当您构建应用程序以进行生产时,您最终会遇到错误。

您可以做的是删除包及其代码。

在你的打字稿文件上使用这些函数并从模板中调用它,你将得到与 ng2-social-share 相同的输出。

在此提供 5 个社交媒体分享 - Facebook、Pinterest、Twitter、GooglePlus、LinkedIn

  // Facebook share won't work if your shareUrl is localhost:port/abc, it should be genuine deployed url
  shareOnFacebook(shareUrl: string) {
    shareUrl = encodeURIComponent(shareUrl);
    window.open(`https://www.facebook.com/sharer/sharer.php?u=${shareUrl}`, 'sharer');
  }

  shareOnPinterest(shareUrl: string, img: string, desc: string) {
    shareUrl = encodeURIComponent(shareUrl);
    img = encodeURIComponent(img);
    desc = encodeURIComponent(desc);
    window.open(`https://www.pinterest.com/pin/create/button?url=${shareUrl}&media=${img}&description=${desc}`, 'sharer');
  }

  shareOnTwitter(shareUrl: string, desc: string) {
    shareUrl = encodeURIComponent(shareUrl);
    desc = encodeURIComponent(desc);
    window.open(`https://twitter.com/intent/tweet?url=${shareUrl}&text=${desc}`, 'sharer');
  }

  shareOnGooglePlus(shareUrl: string) {
    shareUrl = encodeURIComponent(shareUrl);
    window.open(`https://plus.google.com/share?url=${shareUrl}`, 'sharer');
  }

  // LinkedIn share won't work if your shareUrl is localhost:port/abc, it should be genuine deployed url
  shareOnLinkedIn(shareUrl: string, title: string, summary: string) {
    shareUrl = encodeURIComponent(shareUrl);
    window.open(`https://www.linkedin.com/shareArticle?url=${shareUrl}&title=${title}&summary=${summary}`, 'sharer');
  }

希望这会对您或其他人有所帮助。 谢谢!

【讨论】:

    猜你喜欢
    • 2019-01-27
    • 2021-08-15
    • 1970-01-01
    • 2019-04-24
    • 2018-03-14
    • 1970-01-01
    • 1970-01-01
    • 2017-12-23
    • 1970-01-01
    相关资源
    最近更新 更多