jQuery不能设置css图像源

时间:2017-04-15 17:00:48

标签: javascript jquery typescript ionic2

您好我有问题,如果我使用它:

$('.tab-button-icon[aria-label="profile"]').css({"background-image": "url('myserver.com/image')"});

有效,但如果我想以编程方式更改网址并将其设置为新变量并不起作用。 我确定this.profilepiclink有正确的网址。

$('.tab-button-icon[aria-label="profile"]').css({"background-image": "url('" + this.profilepiclink + "')"});

这就是我使用它的方式:

export class MainActivity
{
  profilepiclink:string = "";

  constructor(public navCtrl: NavController,  private auth: AuthService, public menu: MenuController, private sanitizer: DomSanitizer)
  {
     this.sanitizer = sanitizer;
     this.menu.swipeEnable(true);
  }

  ionViewWillEnter(){
    NativeStorage.getItem('loginprofilepicture').then( data => this.profilepiclink = data, error => this.profilepiclink = "http://myserver/image");
    console.log(this.profilepiclink);
    //$('.tab-button-icon[aria-label="profile"]').css({"background-image": "url('http://server/image')"});
    $('.tab-button-icon[aria-label="profile"]').css({"background-image": "url('" + this.profilepiclink + "')"});
  }

0 个答案:

没有答案