sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

SPFX and angular5 : how to get promises values in template

Open bouhmid86 opened this issue 8 years ago • 2 comments

  • [x] Question
  • [ ] Typo
  • [ ] Bug
  • [ ] Additional article idea

Hello,

I'm new to sharepoint SPFX developement , i'm creating a client webpart using angular js 5 (based on sahil malik tutorial) for now i want to display a simple array of numbers returned from a promise in the template component :`@Component({ selector: 'app-root', templateUrl: './app.component.html'

})

export class AppComponent implements OnInit {

promise: Promise<number[]>; public array: Array; ngOnInit() { this.promise = new Promise((resolve, reject) => { resolve([1, 2, 3, 4, 5, 6]); }); this.promise.then((data: Array) => { this.array = data; console.log(this.array) }); } }`

in app.component.html : <p *ngIf="!array">Waiting for values</p><p *ngFor="let a of array">{{a}}</p>

the array is always undefined in template (but in console i have my array) , any help and thanks for advance

bouhmid86 avatar Aug 29 '18 09:08 bouhmid86

According to your description, I have modified your code.It runs successfully. The code like this:

' @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit {

title = 'hello-world'; array: Array; promise: Promise<number[]>;

ngOnInit(): void { this.promise = Promise((resolve) => { resolve([1,2,3,4,5]); }); this.promise.then((data: Array) =>{ this.array = data; console.log(this.array); })

}

} '

The 'app.component.html' like this:

'

Waiting for the Values

{{item}}

'

KingKangMSFT avatar Aug 31 '18 01:08 KingKangMSFT

This issue is being closed as part of an issue list cleanup project. Issues with no activity in the past 6 months that aren't tracked by engineering as bugs were closed as part of this inititive. If this is still an issue, please follow the steps outlined to re-open the issue.

msft-github-bot avatar Jan 22 '20 21:01 msft-github-bot