【发布时间】: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 中分享页面
-
你能发布你的组件的代码和模板吗?