1

does anyone know how to get my code working. I'm trying to make a user creation dialog and want to send post data using ngResource, I've already configured my PHP backend and its working as expected. Now, my problem is appending errors on the dialog, I've tried adding dummy data but ngRepeat does not work for me. I've also tried different steps debugging the problem but nothing works for me. I've also researching about the issue but no luck. here is my code:

<div name="errors" id="errors" class="alert alert-error">
        <li ng-repeat="error in dialog.errors">{{ error }}</li>
</div>

try to look at the link http://jsfiddle.net/QCQrF/

1 Answer 1

6

@Ryan there were number of things going on in your jsFiddle but the most important problem was the way you were specifying dialog's template. A template can be either specify as string (using the template property) or as a partial (templateUrl).

If you move a template to a partial you can specify it like follows:

var dialogOpts = {
        backdrop: true,
        keyboard: true,
        backdropFade: true,
        backdropClick: true,
        templateUrl:  'login-dialog.html',
        controller: 'DialogCtrl',
        resolve: { dialogScope : {
          errors : ['error1', 'error2'],
          title :'Add User',
          btnTxt : 'Create User'
        }}
    };

Also, IMO it is easier to pass data to be exposed on the dialog's scope using the resolve property instead of using dialog's instance.

I've converted your fiddle to a plunk to show this: http://plnkr.co/edit/iGIwPBj9zBPgX3IUwBNj?p=preview

You might find $dialog's service additional documentation helpful in further exploaration of this service: https://github.com/angular-ui/bootstrap/blob/master/src/dialog/README.md

As the last remark, I've noticed that you are were passing the $event argument to event handlers (all calling preventDefault() on them) while this is unnecessary.

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

5 Comments

Just was going to give same answer :) One note here: @Ryan, if you need to embed html template of dialog into same view where you're calling it, you can use <script type='text/ng-template' id='login-dialog.html'>...template</script> so you will reduce 1 call to back end.
@Valentyn Shybanov Great :-) And good note. In my apps I'm pre-loading templates as described here stackoverflow.com/a/12346901/1418796 so back-end would be called for a template anyway. But yes, you've got definitively a valid point here!
@pkozlowski.opensource Thanks you so much..one more thing, what is the best way to reduce server traffic?..In my case I plan to render all my templates inside single HTML file using PHP then select the element(e.g jquery) and pass it to the template as a string...does that solve the problem of reducing server(Apache/PHP) traffic?..or does that makes angular slow?...what is the best practice?
pkozlowski.opensource and @Valentyn Shybanov , I guess you both already answered my question..ng-template works nicely for me...sorry I was only reading pkozlowski's answer till I viewed the comments..thank you so much guys...you really helped me a lot!
@Ryan, I would advice strongly against using jQuery to grab content of templates. AngularJS has already excellent mechanism for this in form of docs.angularjs.org/api/ng.directive:script. Please, really do check this SO question for more details: stackoverflow.com/a/12346901/1418796

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.