I am trying to figure out form validation in Angular 2. Right now I have an add product form that is adding a product to a particular store's inventory. I want to validate that the product's price is more than the wholesale price of the product, so I added the wholesale price as a data-*
attribute. What I can't figure out is how to reference that attribute with Angular 2's NgControl. Here is my code:
...
<div class="four wide field">
<label>Wholesale Price</label>
<div class="ui left icon input">
<input type="text" disabled [(ngModel)]="wholesalePrice" ngControl="wholesale" />
<i class="dollar icon"></i>
</div>
</div>
<div class="four wide field">
<label>Price</label>
<div class="ui left icon input">
<input type="text" [(ngModel)]="retailPrice" [attr.data-wholesale]="wholesalePrice" ngControl="price" required />
<i class="dollar icon"></i>
</div>
</div>
...
...
constructor(private fb: FormBuilder) {
this.form = fb.group({
price: ['price', Validators.compose([
Validators.required,
this.validator_moreThanWholesale
])],
quantity: ['quantity']
});
}
...