I Create custom directive to check the value input and if it is not the same as total of household members then show error message to pay user attention that he input the wrong value.
app.directive('exact',
function () {
var link = function ($scope, $element, $attrs, ctrl) {
var validate = function (viewValue) {
var comparisonModel = $attrs.exact;
if (!viewValue || !comparisonModel) {
// It's valid because we have nothing to compare against
ctrl.$setValidity('exact', true);
}
if (parseInt(viewValue) != parseInt(comparisonModel)) {
ctrl.$setValidity('exact', false);
return viewValue;
} else {
ctrl.$setValidity('exact', true);
return viewValue;
}
};
ctrl.$parsers.unshift(validate);
ctrl.$formatters.push(validate);
$attrs.$observe('exact', function (comparisonModel) {
return validate(ctrl.$viewValue);
});
};
return {
require: 'ngModel',
link: link
};
}
);
this should set validity of input to false if the input is not equal to the {{total}} value
<md-input-container class="md-block">
<input required type="number" exact="{{total}}"name="num" ng-model="house.No" style="max-width:100px;">
<div ng-messages="Form.num.$error" multiple>
<div ng-message="required">Please provide Total Household Members.</div>
<div ng-message="exact">According to your input in step 1 and step 3(part B), your total Household Members is {{total}} </div>
</div>
</md-input-container>