简体   繁体   中英

Angular Partial Routes not working using ng-view

My template page renders fine but my scope text and my partials do not display. I created a link to click on Status ... but it doesnt render anything in my ng-view within my template. Up to my neck in trying to figure out something that should be simple... seems complicated but I know im missing something.

var app= angular.module('myApp', ['ngRoute','flightforms']);

app.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/login', {
  templateUrl: 'partials/login.html', 
  controller: 'loginCtrl'
});

$routeProvider.when('/home', {
  templateUrl: 'partials/default.html', 
  controller: 'homeCtrl'
});

$routeProvider.when('/home/:users', {
  templateUrl: 'partials/subpgs/users.html', 
  controller: 'userCtrl'
});

$routeProvider.when('/home/:status', {
  templateUrl: 'partials/subpgs/status.html', 
  controller: 'statusCtrl'
});

$routeProvider.when('/ao-obsvao', {
  templateUrl: 'partials/subpgs/aobsrv.html', 
  controller: 'obsvaoCtrl'
});

$routeProvider.when('home/:obs-bkoff', {
  templateUrl: 'partials/subpgs/obsbkoff.html', 
  controller: 'obsbkoffCtrl'
});

$routeProvider.when('/home/:fieldmgr', {
  templateUrl: 'partials/subpgs/fieldopmgr.html', 
  controller: 'fieldmgrCtrl'
});

$routeProvider.when('/home/:dispatch', {
  templateUrl: 'partials/subpgs/disp.html', 
  controller: 'dispatchCtrl'
});

my controllers:

var flightforms = angular.module('flightforms', []);

app.controller('homeCtrl', ['$scope','loginService','$http','flightforms',
function($scope,loginService,$http,flightforms){
$scope.txt='Logged in...';
$scope.logout=function(){
    loginService.logout();
}
}]);

app.controller('dispatchCtrl', ['$scope','$routeParams', function($scope,$routeParams){
$scope.txt='You are logged in';
$scope.logout=function(){
    loginService.logout();
}
}]);

flightforms.controller('fieldmgrCtrl', ['$scope','$routeParams', function($scope,$routeParams){
$scope.txt='You are logged in';
$scope.logout=function(){
    loginService.logout();
}
}]);

flightforms.controller('obsbkoffCtrl', ['$scope','$routeParams', function($scope,$routeParams){
$scope.txt='You are logged in';
$scope.logout=function(){
    loginService.logout();
}
}]);

my default.tpl.html page has a ng-view within it which seems to be credible but doesnt display anything when i click on my link. I instead get a 401 page not found.

default.tpl.html

<section class="main-section">
<div>
<p>{{txt}}</p>
    <div ng-view>Loading...</div>
</div>
</section>

And im just noticing this error/warning:

"Error: [$injector:unpr] Unknown provider: flightformsProvider <- flightforms

The first controller of your flightform module is trying to inject a service, flightform , that does not exist.

app.controller('homeCtrl', ['$scope','loginService','$http','flightforms',
function($scope,loginService,$http,flightforms){
$scope.txt='Logged in...';
$scope.logout=function(){
    loginService.logout();
}
}]);

I suggest you remove that injected service or create it.

现在将我的配置切换到ui-route,一切正常。

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