I'm trying to update my weatherApp input field
<input type="number" class="hidden-input" ng-model="updatedWeather.SurfaceWind.Gust" winds></input>
by using an Angular Directive:
.directive('winds', windDirective);
function windDirective () {
return {
restrict: 'A',
require: 'ngModel',
scope : { ngModel : '=?'},
link: function (scope, element, attrs, ngModel) {
element.bind('change', function () {
console.log(ngModel);
scope.$apply(setAnotherValue());
});
function setAnotherValue() {
ngModel.$setViewValue("hello!");
console.log(ngModel);
ngModel.$render();
}
}
};
}
I declared the directive and controller before this, and everything seems to be running (successfully logging to console). But for some reason, whenever I try and change my input field, the value defaults to 0, and nothing displays. Any help would be appreciated!
ng-change
to call a function whenever it changes and updateupdatedWeather.SurfaceWind.Gust
there