Angular2 - subscribe to Service variable changes

后端 未结 4 697
时光说笑
时光说笑 2021-01-30 15:01

I have an authentication service that makes the authenticated variable equal to true or false.

checkAuthentication(){
  this._authService.getAuthentication()
           


        
4条回答
  •  灰色年华
    2021-01-30 15:39

    I used a {{ showValue() }} in the component template, and in the .ts file I called the service's variable

    showValue() {
       this.authenticated = this._authService.authenticated;
       return "dummy"
    } 
    

    Thanks to Angular2's GUI 2-way binding, it works.

提交回复
热议问题