<h1>Hello,World</h1> <p>你好,gundam meister</p> <span>海牛高达</span> <div> <span>海牛高达</span> <span>NewType</span> </div>
@Component({
selector: 'my-app',
template: `
<h1>Hello,World</h1>
<p>你好,gundam meister</p>
<span>{{name}}</span>
<div>
<span>{{name}}</span>
<span>{{type}}</span>
</div>
`
})
export class AppComponent {
name = '海牛高达';
type = 'NewType';
}
class Gundam {
name: string;
type: string;
}
gundam: Gundam = {
name: '海牛',
type: 'NewType'
};
<h1>Hello,World</h1>
<p>你好,gundam meister</p>
<span>{{gundam.name}}</span>
<div>
<span>{{gundam.name}}</span>
<span>{{gundam.type}}</span>
</div>
const gundams: Gundam[] = [
{name: '海牛高达', type: 'NewType'},
{name: '巴巴托斯', type: '近战'},
{name: '力天使', type: '射击'}
];
gundams = GUNDAMS;
<h1>Hello,World</h1>
<p>你好,gundam meister</p>
<div *ngFor="let gundam of gundams">
<span>
{{gundam.name}}
</span>
</div>
<div>
<span>{{gundam.name}}</span>
<span>{{gundam.type}}</span>
</div>
<div *ngFor="let gundam of gundams" (click)="onSelected(gundam)">
selectedGundam: Gundam; // 定义一个selectedGudam作为接收详情的变量
onSelected (gundam: Gundam) : void{
this.selectedGundam = gundam; // 通过参数赋值
}
<div>
<span>{{selectedGundam.name}}</span>
<span>{{selectedGundam.type}}</span>
</div>
<div *ngIf="selectedGundam">
<span>{{selectedGundam.name}}</span>
<span>{{selectedGundam.type}}</span>
</div>
import {
Component
} from '@angular/core';
class Gundam {
name: string;
type: string;
}
const GUNDAMS: Gundam[] = [
{name: '海牛高达', type: 'NewType'},
{name: '巴巴托斯', type: '近战'},
{name: '力天使', type: '射击'}
];
@Component({
selector: 'my-app',
template: `
<h1>Hello,World</h1>
<p>你好,gundam meister</p>
<div *ngFor="let gundam of gundams" (click)="onSelected(gundam)">
<span>
{{gundam.name}}
</span>
</div>
<div *ngIf="selectedGundam">
<span>{{selectedGundam.name}}</span>
<span>{{selectedGundam.type}}</span>
</div>
`
})
export class AppComponent {
gundam: Gundam = {
name: '海牛',
type: 'NewType'
};
gundams = GUNDAMS;
selectedGundam: Gundam; // 定义一个selectedGudam作为展示详情的变量
onSelected (gundam: Gundam): void {
this.selectedGundam = gundam; // 通过参数赋值
}
}
import { Gundam } from '../../model/gundam';
import { Gundam } from './../model/gundam';
export const GUNDAMS: Gundam[] = [
{name: '海牛高达', type: 'NewType'},
{name: '巴巴托斯', type: '近战'},
{name: '力天使', type: '射击'}
];
import { GUNDAMS } from './../../service/data';
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有