Angularjs: Manipulate The $scope Of An Unknown $element
New to Angular. I'm creating a directive (attribute) for global use through the whole project. I'm using a local storage function and my intention is to have the element, on which
Solution 1:
Your directive should probably manipulate the value through the ngModel
controller (docs):
.directive("loadstorage", function (localStorage) {
return {
require: ["ngModel"],
link: function(scope, element, attrs, controllers) {
var ngModel = controllers[0],
val = localStorage.get(attrs.loadstorage);
element.val(val);
ngModel.$setViewValue(val);
}
};
});
See forked plunk: http://plnkr.co/edit/DZwTgrVNeLIbLXryscPy
Post a Comment for "Angularjs: Manipulate The $scope Of An Unknown $element"