I have a directive that will use ng-model
to expose its value.
The question is that this directive have internal components that will also mess the scope, so I need to isolate its scope, but still preserve ng-model
bind to outside world.
How would I achieve this?
This is the directive:
angular.module('app', []).directive('myDirective', function() {
return {
restrict: 'E',
require: 'ngModel',
link: function(scope, element, attr, ngModel) {
// do stuff using ngModel controller
},
replace: true,
template: '<div><input ng-model="userInput" /></div>'
};
});
<my-directive ng-model="prop"></my-directive>
As you can see, the directive must expose prop
as its value, but should not expose userInput
in the parent scope, defined in <input ng-model="userInput"/>
.
How would I be able to make only prop
available in the parent scope?