Please can anybody explain why this code doesnt work, i try set input types dynamically, but this is not working.
//our root app component
import {Component, NgModule, VERSION} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import { FormsModule } from '@angular/forms';
@Component({
selector: 'my-app',
template: `
<form #f="ngForm">
<input [type]="rtype" value="beef" name="food" [(ngModel)]="myFood"> Beef
<input [type]="rtype" value="lamb" name="food" [(ngModel)]="myFood"> Lamb
<input [type]="rtype" value="fish" name="food" [(ngModel)]="myFood"> Fish
</form>
<p>Form value: </p> <!-- {food: 'lamb' } -->
<p>myFood value: </p> <!-- 'lamb' -->
`,
})
export class App {
name:string;
myFood = 'lamb';
rtype='radio';
constructor() {
this.name = `Angular! v${VERSION.full}`
}
}
@NgModule({
imports: [ BrowserModule,FormsModule ],
declarations: [ App ],
bootstrap: [ App ]
})
export class AppModule {}
also i try use type=
, but this also doesnt work
I am read this http://ift.tt/2sTHNtK. But not understand why it is not working in Angular. May be angular not call http://ift.tt/2wQQdo6. Please explain.
Also when i create simple radio in html< and then try change the input type property from console it works fine for example was input.type="radio", became input.type="checkbox" in browser i see that radio changed to the normal checkbox.
Aucun commentaire:
Enregistrer un commentaire