Created
March 30, 2016 18:15
-
-
Save bignimbus/e2609bacb1caaf0d57197c593058ac45 to your computer and use it in GitHub Desktop.
Inheriting ngModel in an Angular directive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myModule', []) | |
.directive('myDirective', myDirective); | |
function myDirective () { | |
return { | |
restrict: 'E', | |
scope: { | |
inputName: '@', | |
model: '=' | |
}, | |
template: '<section>' | |
+ '<input type="text" name="{{inputName}}" ng-model="model[inputName]"></input>' | |
+ '</section>' | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form> | |
<input type="text" name="bar" ng-model="foo.bar"></input> | |
<input type="text" name="baz" ng-model="foo.baz"></input> | |
<my-directive model="foo" input-name="bing"> | |
<!-- foo.bing is bound to the input in the my-directive template --> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment