Created
October 29, 2014 05:46
-
-
Save jamlfy/aaaafb920fb5a0874972 to your computer and use it in GitHub Desktop.
In Value
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
| <section in-value="bla" ng-model="myModel"> | |
| <p>{{myModel}}</p> | |
| </section> | |
| <section in-value="23" ng-model="other.bla"> | |
| <p>{{other.bla}}</p> | |
| </section> | |
| <section in-value="23" ng-model="other.blas.other"> | |
| <span in-value="other" ng-model="other.a" >{{other.a}}</span> | |
| <input type="text" ng-model="other.blas.other" /> | |
| </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
| angular.directive('inValue',[ function () { | |
| return { | |
| restrict: 'A', | |
| require: 'ngModel', | |
| link : function(scope, elez, attrs) { | |
| var is = attrs.ngModel.split('.'); | |
| var spz = is[0]; | |
| is.splice(0,1); | |
| if( !scope[ spz ] ) | |
| scope[ spz ] = {}; | |
| if( is.length < 1 ) | |
| scope[ spz ] = attrs.inValue; | |
| var strObj = ''; | |
| for (var i = 0; i < is.length; i++) { | |
| var val = is[ i + 1 ] ? '{}' :'"' + attrs.inValue + '"' ; | |
| strObj += '.' + is[i]; // if( is[ i + 1 ] || !is[ i - 1 ] ) | |
| scope.$eval( spz + strObj + '='+ val + ';' ); | |
| } | |
| } | |
| }; | |
| }]) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Insert init with clean html!!