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/

Ryan
  • 151
  • 3
  • 11

1 Answers1

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.

pkozlowski.opensource
  • 117,202
  • 60
  • 326
  • 286
  • 3
    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 `` so you will reduce 1 call to back end. – Valentyn Shybanov Jan 26 '13 at 17:51
  • 1
    @Valentyn Shybanov Great :-) And good note. In my apps I'm pre-loading templates as described here http://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 Jan 26 '13 at 18:09
  • @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? – Ryan Jan 27 '13 at 08:33
  • 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 Jan 27 '13 at 09:05
  • @Ryan, I would advice strongly against using jQuery to grab content of templates. AngularJS has already excellent mechanism for this in form of http://docs.angularjs.org/api/ng.directive:script. Please, really do check this SO question for more details: http://stackoverflow.com/a/12346901/1418796 – pkozlowski.opensource Jan 27 '13 at 09:06