I've got an AngularJS app with pages built using Smarty. The top of the page has the ng-agg
tag parameter, and basic AngualarJS templates are being compiled, and the .run
method of my my module is being run, but my controller is not being called
Start of the html
<!DOCTYPE html>
<html ng-app="myapp">
...
$routeProvider
angular.module('myapp', function($routeProvider, $locationProvider) {
$routeProvider
.when('/index.php?page=tutorial', {controller: 'MyappTutorial'})
.when('/index.php?page=home', {controller: 'MyappHome'})
.when('/index.php?page=login', {controller: 'MyappLogin'})
})
Tutorial controller
var MyappTutorial = function ($scope, $location) {
console.log('tutorial');
}
When I visit the page index.php?page=tutorial I my angular page template is built and a console.log() in my myapp.run()
method is triggered, but the tutorial controller doesn't run.
How do I go about debugging this. I'm guessing it's the routeProvider going wrong, is there a way of me checking which controller is being used, if any.
I'm not getting any errors in my javascript console.
This is running in Chrome, from a local development Ubuntu virtual machine, on a Mac.
I think that you may want to reconsider how you are structuring your project. I tried something like you have and it doesn't seem right to me (and was unable to make it work).
I'm using php (outside of my job) and .net (at my job) with angular and the conclusion I came to, a while back, was that its far easier to work within the box, meaning, (IMHO) abandon smarty, abandon php templates and use angular as your client side and use php for your server side. Its not to say you can't have an index.php, however, you can use partials (php or html). You will find a much simpler structure whereby you have html, js (review tutorial routing and multiple views in the tutorials). You should realize that there are things you need to be aware of when you use partials (particularly on using # and html5mode).
However, you didn't ask for my opinion -- and I may get dinged for it... To answer your question. I think that if want to keep the structure that you have, then you should put the controller inside of your template attached to a container .
Hope this helps
--dan