我想要在Angular 中使用for循环,这是我在app.component.ts
中的代码
export class AppComponent {
title = 'CatsBookProject';
postText =[
'Hello , i am here to meet new friends and make a friends relationship',
'Hello everyone, Iam glad you are here',
'Hey, my name is Susanne. I amm 2 years old',
'I like eating cookies.'
]
postImgs = [
'assets/Imge/img1.png',
'assets/Imge/im21.png',
'assets/Imge/img3.jpg',
'assets/Imge/img4.jpg',
]
buttonClicked(){
alert("What's up");
}
}
and this in `app.componwnt.html`
[![enter image description here](https://i.stack.imgur.com/0IDE4.png)](https://i.stack.imgur.com/0IDE4.png)
<;app-stroy*ngFor=‘let i of[0,1,2,3]’[img]=‘postImgs[0]’[Text]=‘postText[0]’>;
and I have this error
[![enter image description here](https://i.stack.imgur.com/a0PPp.png)](https://i.stack.imgur.com/a0PPp.png)
NG0303:无法绑定到‘ngForOf’,因为它不是‘app-stroy’的已知属性(在‘_AppComponent’组件模板中使用).
- 如果‘app-stroy’是一个Angular 组件,并且它具有‘ngForOf’输入,则验证它是否包含在该组件的‘@Component.Imports’中.
- 如果‘app-stroy’是Web组件,则将‘CUSTOM_ELEMENTS_SCHEMA’添加到此组件的‘@Component.schemas’以取消显示此消息.
- 若要允许任何属性,请将‘NO_ERROR_SCHEMA’添加到此组件的‘@Component.schemas’中.
this is the code in `story.component.ts `
import { Component, Input, OnInit } from '@angular/core';
@Component({
selector: 'app-stroy',
standalone: true,
imports: [],
templateUrl: './stroy.component.html',
styleUrl: './stroy.component.scss'
})
export class StroyComponent implements OnInit{
@Input() text:string='';
@Input() img :string='';
constructor(){ }
ngOnInit(): void {
}}
and this is in
> app.component.ts
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import {HeaderComponent} from './header/header.component';
import {StroyComponent} from './stroy/stroy.component';
import { NgModel } from '@angular/forms';
@Component({
selector: 'app-root',
standalone: true,
imports: [RouterOutlet, HeaderComponent, StroyComponent],
templateUrl: './app.component.html',
styleUrl: './app.component.scss'
})
export class AppComponent {
title = 'CatsBookProject';
postText =[
'Hello , i am here to meet new friends and make a friends relationship',
'Hello everyone, Iam glad you are here',
'Hey, my name is Susanne. I amm 2 years old',
'I like eating cookies.'
]
postImgs = [
'assets/Imge/img1.png',
'assets/Imge/im21.png',
'assets/Imge/img3.jpg',
'assets/Imge/img4.jpg',
]
buttonClicked(){
alert("What's up");
}}
maybe some one know why ??
I need some help.