简体   繁体   中英

AngularJS 1.3 Routing not working; Controller never called

I can't for the life of me get AngularJS to work properly. I am not messing with templates or anything of that nature yet, I'm just trying to get the call to the controller to work correctly.

Here is a portion of my homepage.html

<div class="row" ng-app="eventsApp">
    <div class="column small-12 content">

        <p>Temporary Test.</p>
        <div ng-view></div>
        <ul class="small-block-grid-2 medium-block-grid-4 large-block-grid-5 shots">
            <li>
                <div class="thumb">
                    <a href="#Testing">
                        <div class="ctr-show s1">
                            <div class="show"><i class="fa fa-search-plus fa-lg"></i></div>
                        </div>
                        <img src="/img/screenshots/thumbs/g" alt="">
                    </a>
                </div>
            </li>
...

Here is my app.js

'use strict';

var eventsApp = angular.module('eventsApp', [
'ngRoute',
'ngSanitize',
]);

alert("testing number 1");

eventsApp.config(['$routeProvider', function($routeProvider){

$routeProvider.
when('/Testing', {
    templateUrl : 'Views/AngularViews/temp.html',
    controller : 'TestingController'
});
}]);

Later on in the app.js....

eventsApp.controller('TestingController', 
function($scope) {
    alert("testing number 2");

});

Can anyone spot what I'm doing incorrectly? It just isn't working at all. The first alert pops up just fine, the second one never pops up, even after using the correct route.

Thanks in advance.

This is my code in coffeescript that works, I cannot spot any error in your implementation (and since there is no error on console...)

App.config [

  '$provide'
  '$routeProvider'

  ($provide, $routeProvider) ->

  $routeProvider
      .when('/testing', {
        templateUrl: 'test.hml'
        controller : 'TestingController'
      })
]

iDsign.App.controller('TestingController', ($scope)->

  alert('something')
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM