I\'m trying to get the value from ngModel from my input through a directive, but I can\'t get the value.
Here is my code:
angular
.module(\'myapp\')
By this sample you can get the first ngModel Value and also onChange Values
var app = angular.module("app", []);
app.controller("controller", function ($scope) {
$scope.test = "hi";
});
app.directive("directiveName", function () {
return {
restrict: "A",
replace: true,
scope: {
directiveName: "="
},
require: "^ngModel",
link: function (scope, element, attr, ngModel) {
var firstValue = scope.directiveName;
console.log("firstValue", firstValue);
element.on("input propertychange", function () {
console.log("onchange", ngModel.$viewValue);
});
}
}
})
{{test}}