2 回答

TA貢獻(xiàn)1828條經(jīng)驗 獲得超3個贊
app.html
<select [(ngModel)]="comId">
<option [value]="c.id" *ngFor="let c of comIdList">{{c.name}}</option>
</select>
<div>
<label *ngFor="let t of typeList">
<input type="radio" (change)="type=t.id" name="type" [checked]="type===t.id">{{t.name}}
</label>
</div>
app.component.ts
@Component({
selector: 'app',
templateUrl: 'src/app.html'
})
export class AppComponent implements OnInit {
comIdList:any = [
{id: 1, name: '中國公司'},
{id: 2, name: '美國公司'},
{id: 3, name: '德國公司'}
];
typeList:any = [
{id: 1, name: '類型A'},
{id: 2, name: '類型B'}
];
comId:number;
type:number;
constructor() {
}
ngOnInit() {
setTimeout(()=> {
this.comId = 3;
this.type = 2;
}, 1000);
}
}

TA貢獻(xiàn)1911條經(jīng)驗 獲得超7個贊
AngularJS提供$http控制,可以作為一項服務(wù)從服務(wù)器讀取數(shù)據(jù)。服務(wù)器可以使一個數(shù)據(jù)庫調(diào)用來獲取記錄。 AngularJS需要JSON格式的數(shù)據(jù)。一旦數(shù)據(jù)準(zhǔn)備好,$http可以用以下面的方式從服務(wù)器得到數(shù)據(jù)。
function studentController($scope,$http) {
var url="data.txt";
$http.get(url).success( function(response) {
$scope.students = response;
});
- 2 回答
- 0 關(guān)注
- 621 瀏覽
添加回答
舉報