【问题标题】:send whatsapp message from angular 2 web app从 Angular 2 Web 应用程序发送 whatsapp 消息
【发布时间】:2017-04-26 10:34:13
【问题描述】:

使用 Angular 2(或 4)构建网络应用。想通过whatsapp发送消息。这工作正常whatsapp://send?text=hi! 从浏览器打开whatsapp。我想发送当前页面的 url。我可以使用 {{url}} 在网页上打印 url,但如果您知道我的意思,我不知道如何设置 text={{url}}。

组件的相关部分`

export class ActivityDetailsComponent implements OnInit {


  @Input() activity: any;
  @Output() close = new EventEmitter();
  error:any;
  navigated = false;
  sub: any;
  imageURL: string;
  location:Location;
  url: any;

  constructor(private activitiesService:ActivitiesService,
                private route: ActivatedRoute,
                private router: Router,
                private pics: PicsService,
                location:Location             

                ) { 

                this.location = location;
                this.url = this.location.path();

                 }

`

相关的html `

    Send a link to this activity to your
     <a href="whatsapp://send?text=http://ec2-52-209-95-130.eu-west-  
 1.compute.amazonaws.com:4200/activities/58c003d47513092fac820f09">whatsapp</a>
     contacts  

    http://ec2-52-209-95-130.eu-west-1.compute.amazonaws.com:4200{{url}}

`

【问题讨论】:

  • 复制 URL 并将其粘贴到任何你想要的地方
  • 从哪里可以访问url 变量?
  • @Amit 我对 www.example.com 部分进行了硬编码,并使用this.url = this.location.path(); 来获取“pageID”部分
  • @RameshRajendran 我希望用户能够通过点击链接在 whatsapp 中分享页面
  • 你能发布你的组件的代码和模板吗?

标签: angular whatsapp


【解决方案1】:

有两种可能的技术可以解决您的问题:

  1. Property binding

我们使用方括号告诉 Angular 解析 href 字段的值。此外,我们使用简单的字符串连接:

<a [href]="'http://example.org/?test=' + url">whatsapp</a>
  1. Interpolation

这是使用大括号的技术,也是您尝试使用的技术:

  <a href="{{'http://example.org/?test=' + url}}">whatsapp</a>

根据您的情况,您可以选择您喜欢的解决方案,官方文档(与上述相同的链接)说明如下:

将数据值呈现为字符串时,没有技术原因 喜欢一种形式而不是另一种形式。你倾向于可读性,这往往 支持插值。你建议建立编码风格规则 并选择既符合规则又最有感觉的形式 对于手头的任务很自然。

【讨论】:

  • 您想通过评论解决什么问题?
  • 这是 whatsap 代码,`text=` 无法翻译 {{url}}
  • 您可以将上面的 url (example.org) 替换为您喜欢的任何字符串。如果您使用显示的 sn-ps 中的一个,则 url 的值将附加到前一个字符串。翻译是什么意思?
【解决方案2】:

使用下面的代码来做

var url = document.URL var red = (url.substr(url.lastIndexOf('=') + 1)); window.location.replace("https://api.whatsapp.com/send?text=" + red);

或者您可以使用下面的永久链接直接进入,无需任何脚本

https://www.educlick.page/p/whats-app-redirect.html?url>url encode<

【讨论】:

    猜你喜欢
    • 2020-06-25
    • 2015-11-25
    • 2018-07-11
    • 1970-01-01
    • 2019-08-03
    • 2011-10-18
    • 2015-11-09
    • 2015-04-17
    • 2017-04-08
    相关资源
    最近更新 更多