i have simple directive:
app.directive('string', function () { return{ template: '<input id="{{field.name}}" name="{{field.name}}" type="text" value="{{field.value}}"/>', restrict: 'e', }; });
that i'm creating in controller:
for(var i=0;i<$scope.steps;i++){ var step = $scope.steps[i]; var element = document.createelement(step.type); var compiled = $compile(element)($scope); $(document.body).append(compiled); }
this outputs textfield without value. how can give directive 'step'
variable , print out in text field step.value
?
you should use ng-repeat
this
<string ng-repeat='field in steps'></string>
update: doing ng-repeat
does
for(var i=0;i<$scope.steps;i++){ var childscope=$scope.$new(); childscope.field=$scope.steps[i]; var element = document.createelement(field.type); var compiled = $compile(element)(childscope); $(document.body).append(compiled); }
Comments
Post a Comment