I'm just looking at the angular 2 meteor tutorial. In step 4, binding the angular 2 form to hash f is equal to the form in order to bind the form to the f variable and secondly to bind the onSubmit function, Doesn’t work for me. Is the angular 2 API modified?
HTML does not work:
<form #f="form" (submit)="addParty(f.value)">
<div>{{f.value}}</div>
</form>
Original HTML for parties-form.html from example:
<form [ng-form-model]="partiesForm" #f="form" (submit)="addParty(f.value)">
<label>Name</label>
<input type="text" ng-control="name">
<label>Description</label>
<input type="text" ng-control="description">
<label>Location</label>
<input type="text" ng-control="location">
<button>Add</button>
<div>{{f}}</div>
<div>{{f.value}}</div>
</form>
And the JS Component-form.ts components:
import {Component, View} from 'angular2/angular2';
import {FORM_DIRECTIVES, FormBuilder, Control, ControlGroup, Validators} from 'angular2/angular2';
import {Parties} from 'collections/parties';
@Component({
selector: 'parties-form'
})
@View({
templateUrl: 'client/parties-form/parties-form.html',
directives: [FORM_DIRECTIVES]
})
export class PartiesForm {
partiesForm: ControlGroup;
constructor() {
var fb = new FormBuilder();
this.partiesForm = fb.group({
name: ['', Validators.required],
description: [''],
location: ['', Validators.required]
});
console.log(this.partiesForm.value);
}
addParty(party) {
console.log("assParty", party);
return true;
if (this.partiesForm.valid) {
Parties.insert({
name: party.name,
description: party.description,
location: party.location
});
(<Control>this.partiesForm.controls['name']).updateValue('');
(<Control>this.partiesForm.controls['description']).updateValue('');
(<Control>this.partiesForm.controls['location']).updateValue('');
}
}
}
console.log("PartiesForm loaded");
I copied the angular 2 meteor sample, see the exact code there. Other samples, such as ng-book , use it also as an onSubmit function
#f="form" (submit)="onSubmit(f.value)"