Angular 插值数据不工作

Angular 插值数据不工作,angular,typescript,Angular,Typescript,我的代码有些问题,我正在尝试实现shariff,这是一个隐私共享模块 我试过这些,但都不起作用: [attr.data-url]="text" attr.data-url="{{text}}" 我试图将当前url数据绑定到shariff标记,但它在ngOnit标记完成对可观察对象的遍历之前解决,导致url仅为“”,而它应该是“区域”/ID”我不确定如何解决此问题 home.comp.html <div class="shariff" data-lang="en" data-orient

我的代码有些问题,我正在尝试实现shariff,这是一个隐私共享模块

我试过这些,但都不起作用:

[attr.data-url]="text"

attr.data-url="{{text}}"
我试图将当前url数据绑定到shariff标记,但它在ngOnit标记完成对可观察对象的遍历之前解决,导致url仅为“”,而它应该是“区域”/ID”我不确定如何解决此问题

home.comp.html

<div class="shariff" data-lang="en" data-orientation="vertical" data-services="[&quot;facebook&quot;,&quot;googleplus&quot;,&quot;twitter&quot;]" data-theme="white" data-title="WildFyre" [attr.data-url]=text></div>

我认为这不是角度问题,而是您正在使用的非角度小部件的问题,它取决于
数据url
属性

试一试


欢迎来到StackOverflow。请检查当前的行为是什么?预期的行为是什么?当前行为只输出“client.wildfyre.net”,而它应该是“client.wildfyre.net/areas/AREA/ID”。这是在ngonit中设置的,但由于某些原因,它不会更新shariff标记中的attr,并且shariff标记使用最初设置的URLF。添加
console.log(This.text)时会打印什么
在这一行之后
this.text=https://client.wildfyre...
?问题中大约有50行代码与问题完全无关。这使得很难找出什么与问题相关,什么与问题无关|||||||||||做了这个和这个:| ||||||||||||||| | this.cdRef.detectChanges();this.text=''+this.areaService.currentAreaName+'/'+post.id;this.showText=true;this.cdRef.detectChanges();console.log(this.text)@CameronGilbert try*ngIf=“text”showText从未定义过,因此ngIf始终结果为false(导致div未呈现)没有将其添加到我的注释中,因为我认为这将被推断:在构造函数之前设置如下:showText:boolean=false;仍然不起作用,更改为ngIf=“text”,显示,但最初的问题是backSorry,我最初的想法略有不同,然后忘记更改
ngIf
。我没有深入讨论如何使用shariff小部件,但我想每次将元素重新添加到DOM后(在我回答中的代码之后),您都需要再次调用JS函数来初始化它。您知道如何继续吗?
    import { Component, OnInit } from '@angular/core';
    import { Response } from '@angular/http';
    import { Post, Area, Reputation } from '../_models';
    import { PostService, AreaService } from '../_services';

    @Component({
      templateUrl: 'home.component.html',
    })
    export class HomeComponent implements OnInit {
      post: Post;
      rep: Reputation;
      model: any = {};
      color = 'warn';
      checked: boolean;
      isCopied = false;
      text = 'https://client.wildfyre.net/';

      constructor(
        private postService: PostService,
        private areaService: AreaService
      ) {
        this.checked = this.areaService.isAreaChecked;

        this.areaService.getAreaRep(this.areaService.currentAreaName)
          .subscribe(reputation => {
            this.rep = reputation;
        });
      }

      ngOnInit() {
        document.getElementById('navB').style.display = '';

        this.postService.getNextPost(this.areaService.currentAreaName)
          .subscribe((post: Post) => {
            this.post = post;
            this.text = 'https://client.wildfyre.net/areas/' + this.areaService.currentAreaName + '/' + post.id;
          });
      }
#shariff [attr.data-url]="text"
@ViewChild('shariff') shariff:ElementRef;

ngOnInit() {
   ...

   this.text = 'https://client.wildfyre.net/areas/' + this.areaService.currentAreaName + '/' + post.id;
   new Shariff(shariff.nativeElement, {
     orientation: 'vertical'
   });