2016-04-26 10 views
0

Ich habe Angular-Express-Bootstrap Seed von https://github.com/jimakker/angular-express-bootstrap-seed heruntergeladen. Ich würde gerne Routing durch angular js ausführen, die perfekt ausgeführt wird. Aber jetzt habe ich ein Problem beim Aufruf 'Controller' in controllers.js.Controller Callback Funktion funktioniert nicht in Angular-Express-Bootstrap Seed

Ich kann meine MyCtrl1 auf diese Weise rufen und gut funktionierend:

function MyCtrl1() { 
    alert('calling Myctrl1..') 
} 
MyCtrl1.$inject = []; 

Aber ob ich so nennen:

var app = angular.module('myApp.controllers', []); 
    app.controller('MyCtrl1', ['$scope', function($scope) { 
     $scope.greeting = 'MyCtrl1'; 
     alert('calling'+ $scope.greeting+"..") 
    }]); 

Die obige Controller Rückruffunktion nicht funktioniert und zeigt diesen Fehler: Uncaught Error: [$injector:modulerr] MyCtrl1 is not defined

Routing Config in app.js:

var app = angular.module('myApp', ['myApp.filters','myApp.controllers','myApp.services', 'myApp.directives','ngRoute']) 
    app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) 
    { 
    $routeProvider 
     .when('/view1', { 
      templateUrl: 'partial/1', 
      controller: MyCtrl1 
     }) 
    $locationProvider.html5Mode(true); 
    }]); 

Ich weiß nicht, warum es nicht funktioniert. Jede Hilfe würde sehr geschätzt werden.

Antwort

0

Schließlich habe ich die Lösung, vermisste ich die Zitate auf den Controller-Namen in $routeProvider

Soln: controller: 'MyCtrl1'

Verwandte Themen