SPFX and angular5 : how to get promises values in template
- [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
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
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
ngOnInit(): void {
this.promise = Promise((resolve) => {
resolve([1,2,3,4,5]);
});
this.promise.then((data: Array
}
} '
The 'app.component.html' like this:
'
Waiting for the Values
{{item}}
'
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.