I'm having trouble with custom directives with <input ...> tags in it's template, when they are inside an angular form.
If you declare an input inside a form, editing the input's field will alter form's properties, like pristine, touched, valid, etc, as expected.
If you declare a custom directive inside a form, say <ac2-string-input ...></ac2-string-input> and it's template includes an input, then if you edit this input's field, it WILL NOT alter the form's property.
Why is that? Is that a bug? Is there any workaround for this?
Below you have an example:
We can have a form component, in app/form.component.ts
import { Component } from '@angular/core'
import { InputComponent } from './input.component'
@Component({
selector: 'ac2-form',
templateUrl: '<build path>/templates/form/form.html',
directives: [InputComponent]
})
export class FormComponent {
item: Object = {
attr1: 'blah',
attr2: 'another blah'
}
constructor(){}
submit(){ console.log(this.item) }
}
with a template templates/form/form.html
<form #f="ngForm" (ngSubmit)="submit()">
<input type="text" name="attr1" [(ngModel)]="item.attr1"/>
<ac2-string-input [obj]="item"></ac2-string-input>
<button type="submit">Submit</button>
</form>
<div>
Pristine? {{f.form.pristine}}
</div>
And ac2-string-input directive is defined in app/form/input.component.ts
import { Component, Input } from '@angular/core'
@Component({
selector: 'ac2-string-input',
templateUrl: '<build path>/templates/form/input.html'
})
export class InputComponent {
@Input() obj: Object;
constructor(){}
}
with a template templates/form/input.html
<input type="text" name="attr2" [(ngModel)]="obj.attr2"/>
If we load the form, there will be two text fields, and the form will be "Pristine"
If we edit the "attr2" field, the form will continue to be pristine, as if the field was not bound to the form!
If we edit the "attr1" field, the form will not be pristine, as expected.

