The mechanism for creating deep ngModel objects

I want to use the angular mechanism for deep nesting of properties, something that uses the ng-model directive. I mean, we can create a very "deep" object in the area by writing: ng-model="data.obj1.prop2.attr3.value4.text" in the view, so I want to do this easily in the controller / service too . I do not want to reinvent the wheel (or use this or this ). Is there something undocumented as angular.create(path_str) ?

+2
source share
1 answer

One way you can achieve is to use the $parse service. It has getter and setter functions that I think can handle what you want

  var getter = $parse('prop1.prop2.prop3.prop4'); var setter = getter.assign; setter($scope,"value1111"); 

See this script http://jsfiddle.net/cmyworld/m7gxn/

And I think it also works

 $scope.$eval("prop2.prop2.prop3.prop4=55"); 
+4
source

Source: https://habr.com/ru/post/959111/


All Articles