Why is my GSP pulling in my AngularJS javascript files but not executing my controller function?

251 Views Asked by At

I have a simple GSP View which contains a reference to 2 bundles being managed by the Grails Resources plugin.

the reference to the core angularjs libraries are in my layout.

A basic representation of the view is like so:

<html ng-application="myapp">
<head>
<meta name="layout" content="main"/>
<title>a title</title>
<r:require modules="index, widgeta"/>
</head>
<body ng-controller="index"> 
<div>
    <widgeta/>
</div>
</body>
</html>

Grails seems to pull everything in just fine, i can even see the myapp.controller('index', function(){}); line get executed.

However; my controller function itself never gets executed. Why not!?

1

There are 1 best solutions below

2
On BEST ANSWER

Silly grails... I took a closer look at what was coming back with the HTML and grails was stripping off the controller and app reference.

Moving both to the first 'div' tag in the body seem to do the trick:

<html>
<head>
<meta name="layout" content="main"/>
<title>a title</title>
<r:require modules="index, widgeta"/>
</head>
<body> 
<div ng-application="myapp" ng-controller="index">
    <widgeta/>
</div>
</body>
</html>