Search code examples
angularjspugpartialangularjs-ng-if

Rendering partial views based on an ngif statement in pug (jade) and angularjs


Is it possible to have 2 separate .pug files be the result of an ng-if statement in a parent template? Something like

ng-if({booleanVar ? pugFile1.pug : pugFile2.pug})

Or any way cleaner than having 2 full pages inside an ngif statement? Thanks everyone


Solution

  • There seem to be a confusion between server side rendering and client side logic.

    If you want to render (server side) one template or an other, it has to be done with a pug if, not an angular if. Also, it won't be dynamic with you client side model.

    If you want to display one template or another one based on the client side model, then you need to use an ng-if (or ng-switch) and both templates will be rendered by the server and send to the browser. You can still use pug includes if you can to split your code.