GSP layout and optional body tag attribute (angular.js)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

GSP layout and optional body tag attribute (angular.js)

Sean Gilligan-2
I'm using angular.js with Grails <http://angularjs.org>.  It is working
well, so far, but I have one annoying issue.

I have a layout.gsp file that includes this line:
<body ng:controller="${pageProperty(name:'body.ng:controller')}" >

And then in my view.gsp I put something like this:
<body ng:controller="TranslateCtrl">

The problem I'm having is that I get an ng:controller="" tag in my
output if I don't want/need ng:controller on the body and leave the
property blank in the view GSP.
In some cases I am forced to do this:
<body ng:controller="NoopCtrl">

Where NoopCtrl() is a dummy controller that is a no-op.

I read that you can't use conditionals on the body tag in the the
layout.gsp file.

Is there a clean way to make the ng:controller property disappear on the
output body tag when it isn't used in the view.gsp?

-- Sean




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: GSP layout and optional body tag attribute (angular.js)

Ravi
There are some issues like http://jira.grails.org/browse/GRAILS-5626 raised on Grails body tag attribute problems. Grails developers have provided un-elegant work around OR marked problems as "Won't fix" because of the underlying complexity. Therefore there is no hope of Grails developers supporting this on body tag. Therefore I used a workaround by introducing one more tag inside body tag to hold the angular attribute:

<body>
    <g:if test="${pageProperty(name:'body.ng-controller')}">
        <div ng-app="${pageProperty(name:'body.ng-controller')}">
    </g:if>

    .....
    your code in the body tag
    ....

    <g:if test="${pageProperty(name:'body.ng-controller')}">
        </div>
    </g:if>
</body>

Hope that helps someone!