AngularJS controller not loading

I have an AngularJS application with pages built using Smarty. At the top of the page there is an ng-agg tag parameter, and the ng-agg base templates are compiled, and my .run method of my module is executed, but my controller is not called

Html start

 <!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'}) }) 

Textbook controller

 var MyappTutorial = function ($scope, $location) { console.log('tutorial'); } 

When am I on the index.php page ? page = tutorial My angular template is created and console.log () in my myapp.run() method starts, but the control controller does not start.

How do I debug this. I assume that routeProvider is going wrong, is there a way to check which controller is being used, if any.

I am not getting any errors in my javascript console.

This works in Chrome from a local Ubuntu virtual machine on Mac.

+4
source share
1 answer

I think you can reconsider how you structure your project. I tried something like you, and it seems implausible to me (and it could not get it to work).

I use php (outside my work) and .net (at my work) using angular and the conclusion I came to some time ago was that it is much easier to work in a box, (IMHO) abandon smarty, give up php templates and use angular as your client side and use php for your server side. It cannot be said that you cannot have index.php, however you can use partials (php or html). You will find a much simpler structure in which you have html, js (a review of the routing tutorial and a few views in the tutorials). You need to understand that there are things you need to know about when you use partial ones (especially when using # and html5mode).

However, you did not ask for my opinion - and I can stroke it ... To answer your question. I think that if you want to keep the structure that you have, then you should put the controller inside your template in a container.

Hope this helps

- given

+3
source

Source: https://habr.com/ru/post/1442682/


All Articles