I have a custom element that uses the directive ng-model
to share its value.
The issue arises because this custom element has internal components that may affect the scope. To address this, I need to isolate the scope while still maintaining the connection with the external world through ng-model
.
How can I accomplish this?
Here is the code for the directive:
angular.module('app', []).directive('myDirective', function() {
return {
restrict: 'E',
require: 'ngModel',
link: function(scope, element, attr, ngModel) {
// perform actions using ngModel controller
},
replace: true,
template: '<div><input ng-model="userInput" /></div>'
};
});
<my-directive ng-model="prop"></my-directive>
As shown, the directive should expose the value of prop
, but not reveal the variable userInput
in the parent scope as defined in
<input ng-model="userInput"/>
.
How can I ensure that only prop
is accessible in the parent scope?