Skip to content

Instantly share code, notes, and snippets.

@jamlfy
Created October 29, 2014 05:46
Show Gist options
  • Select an option

  • Save jamlfy/aaaafb920fb5a0874972 to your computer and use it in GitHub Desktop.

Select an option

Save jamlfy/aaaafb920fb5a0874972 to your computer and use it in GitHub Desktop.
In Value
<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>
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 + ';' );
}
}
};
}])
@jamlfy
Copy link
Author

jamlfy commented Oct 29, 2014

Insert init with clean html!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment