value not updating in the view after data update , angular2 and typescript

前端 未结 2 1196
情书的邮戳
情书的邮戳 2021-01-23 23:04

this is my ngOnInit function

 instance.input = document.getElementById(\'google_places_ac\');
        autocomplete = new google.maps.places.Autocomp         


        
相关标签:
2条回答
  • 2021-01-23 23:33

    You should use property binding by wrapping attribute inside []

    <input id="google_places_ac" [attr.state]="state" [attr.country]="coutnry" 
     name="google_places_ac" type="text" [value]="city" class="form-control" />
    

    Additional thing is, you made typo while writing country like you wrotecoutnry instead in two places.

    this.sharedService.country = this.coutnry; //in constructor
    
    attr.country="{{coutnry}}" //second place
    
    0 讨论(0)
  • 2021-01-23 23:39

    you can check this angular2 official docs for setting up the attributes,

    cheatsheet - https://angular.io/docs/ts/latest/cheatsheet.html

    <input id="google_places_ac" [attr.state]="state" [attr.country]="coutnry"
    name="google_places_ac" type="text" value="{{city}}" class="form-control" />
    

    Update

    import { Component, ChangeDetectorRef } from 'angular2/core';
    
    constructor(private cdr:ChangeDetectorRef) {
    }
    public setValue(a,b,c) {
        this.coutnry = a;
        this.state = b;
        this.city = c;
        this.sharedService.country = this.coutnry;
        this.sharedService.city = this.city;
        this.sharedService.state = this.state;
        console.log(a, b, c);
        this.cdr.detectChanges();
    }
    
    0 讨论(0)
提交回复
热议问题