0

I'm new to Angular.js. I have simple application which has dynamic form. I use this plugin in my app.

I have API which returns the json response with controls to be loaded on page. In success callback I assign scope variable response but it doesn't seems to be working. Here is my code http://plnkr.co/edit/YTKloQpeiTTSEx4zVIAI?p=preview

2
  • Can you tell us more about the failure? Is there a failure or is your form just not populated? It would also be nice to know if the ajax call has actually be made or not. Commented Jun 17, 2014 at 14:52
  • angular after 1.0.8 (don't know exact version) has very useful ngIf directive. So you could do <dynamic-form ng-if="loaded" template="stdFormTemplate" ng-model="stdFormData"></dynamic-form> – and it would render just after data is loaded. On your place I would update angular or google an old version of ngIf directive that had place in angular-ui plugins pack a long time ago (I remember because i used it then). Commented Jun 17, 2014 at 15:07

1 Answer 1

1

I’ve spend few minutes to fix this directive to watch attribute changes

 $scope.$watch(attrs.template, function(newValue, oldValue) {
   if (newValue === oldValue) { 
     return;
   }

   //  Grab the template. either from the template attribute, or from the URL in templateUrl
   (attrs.template ? $q.when($parse(attrs.template)($scope)) :
     $http.get(attrs.templateUrl, {
       cache: $templateCache
     }).then(function(result) {
       return result.data;
     })
    )

http://plnkr.co/edit/BWXlsvJ73yeTumh83wqh?p=preview

Sign up to request clarification or add additional context in comments.

1 Comment

Don't like approach with editing third-party libraries. If author will update library, it'll become more complicated to update on our side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.