0

I'm using ngRoute in my site, it work well on my computer (local) but on the server routing doesn't work. On my computer all my files are html, on the server i rename them as php. How can i fix it?

var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider, $compileProvider) {
    $routeProvider
    .when("/", {
        templateUrl : "pages/main.php",
        controller: 'oneCtrl'
    })
    .when("/about", {
        templateUrl : "pages/about.php"
    })
    .when("/news", {
        templateUrl : "pages/news.php"
    })
});
4
  • 1
    Define "doesn't work". Open your dev tools and look at the network requests. What is being requested, and what fails? For what reason? Now look at your server logs - are there any errors? Commented Aug 9, 2016 at 22:07
  • What do you mean by "doesn't work"? Commented Aug 9, 2016 at 22:08
  • I have some progress here :) at first i dounload angular.js file and put on the server - it doesn't work, but now i link to hosted libraries it works, Error Uncaught TypeError: Cannot read property 'module' of undefined Second error routes.js:1 Uncaught ReferenceError: angular is not defined Commented Aug 9, 2016 at 22:12
  • 1
    Looks like you not include angular Commented Aug 9, 2016 at 22:27

1 Answer 1

2

Based on the error messages you're getting (as you said in the comments), the Angular library is not being loaded. Double-check the URL. Also in the browser dev tools, check the Network tab and see what error it shows. Probably a 404 not found.

After checking your website and the line where you said the error was occurring (line 156 of route.js), change your code to this:

    $('.counter-one span').eq(0).html(value1 + ' ');
    $('.counter-two span').eq(0).html(value2 + ' ');

You did a search/replace for "html" to "php" but that also replaced the jQuery html() command. Just fix these two lines and you should be good.

Sign up to request clarification or add additional context in comments.

3 Comments

You need to make sure that Angular can load. The quickest way to test/fix this is to use an external Angular library such as https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.js. If you want to include the JS file on your server, make sure it's in the correct directory and that it has the right permissions.
some controllers don't work error routes.js:156 Uncaught TypeError: $(...).eq(...).php is not a function
I see your problem. You did a search/replace for "html" -> "php" which changed your URLs but it also changed your jQuery code. See my updated answer where I'll post the fix.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.