$routeProvider with templateURL not working

951 views
Skip to first unread message

Oswaldo Roberto Marques

unread,
Jul 12, 2015, 8:07:40 PM7/12/15
to ang...@googlegroups.com

I am using $routeProvider in AngularJS with templateURl and my problem is that nothing happened, nothing shows on console and network tabs on dev tools (Chrome or Firefox). If i use template it works.

Bellow follows the hmtl and js files.

mainPainelAdmin.html (dir: view/admin/)

<!DOCTYPE html>
<html ng-app="adminCondominio">
<head>
<meta http-equiv="content-type" content="charset=UTF-8">
<title>Condomínio Ilha de Bari - Painel Administrador</title>

<!-- Font Awesome CSS available via CDN; version 4.3.0 used here -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">

<!-- Angular Material CSS now available via Google CDN; version 0.10 used here -->
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/0.10.0/angular-material.min.css">

<!-- Angular Material Dependencies -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-route.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-aria.min.js"></script>

<!-- Angular Material Javascript now available via Google CDN; version 0.10 used here -->
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.10.0/angular-material.min.js"></script>


<script type="text/javascript" src="../../js/app.js"></script>
<script type="text/javascript" src="../../js/controllers/admin/mainPainelAdmin.js"></script>
<script type="text/javascript" src="../../js/controllers/admin/menuPainelAdmin.js"></script>
<script type="text/javascript" src="../../js/controllers/admin/mainAdmin.js"></script>
<script type="text/javascript" src="../../js/controllers/admin/adminController.js"></script>
<script type="text/javascript" src="../../js/controllers/admin/configController.js"></script>

<link rel="stylesheet" href="../../css/admin/mainPainelAdmin.css">
<link rel="stylesheet" href="../../css/admin/menuPainelAdmin.css">

</head>
<body>
<div ng-controller="MainPainelAdminCtrl">
<md-content>
<md-toolbar class="md-toolbar-tools">
<md-button class="md-icon-button" aria-label="Settings">
<md-icon class="fa fa-bars fa-lg"></md-icon>
</md-button>
<h2>
<span>Condomínio Ilha de Bari - Administrador</span>
</h2>
<span flex></span>
<md-button class="md-raised md-warn" aria-label="Sair" style="padding-right: 5%" ng-click="logOff()">
<md-icon class="fa fa-sign-out fa-lg" style="color: white; padding-left: 50%"> Sair </md-icon>
</md-button>
</md-toolbar>
<section layout="row" flex ng-controller="MenuPainelAdmin">
<md-sidenav class="md-sidenav-left md-whiteframe-z2" md-component-id="left" md-is-locked-open="true">
<md-list>
<md-list-item class="mouseOver" ng-repeat="item in menuItens">
<p class="menuItemBotao {{item.icon}}" ng-click="go(item.ref)"> {{ item.name }} </p>
</md-list-item>
</md-list>
</md-sidenav>
<md-content flex layout-padding>
<div layout="column" layout-fill layout-align="top center">
<div ng-view></div>
</div>
<div flex></div>
</md-content>
</section>
</md-content>
</div>
</body>
</html>


app.js (dir: js/)

var app = angular.module('adminCondominio',['ngMaterial', 'ngRoute']);


menuPainelAdmin.js (dir: js/controllers/admin/)

app.controller('MenuPainelAdmin', function($scope, $location){
$scope.menuItens = [
{name: 'Início', icon:'fa fa-home fa-lg', ref:'home'},
{name: 'Administração', icon:'fa fa-briefcase fa-lg', ref:'admin'},
{name: 'Configurações', icon:'fa fa-cogs fa-lg', ref:'configs'}
];

$scope.go = function ( path ) {
$location.path( path );
};
});

app.config(['$routeProvider', function($routeProvider){
$routeProvider
.when('/home', {
templateURL: '/view/admin/inicioAdmin.html',
controller: 'MainAdmin'
})
.when('/admin', {
templateURL: '/view/admin/administracaoAdmin.html',
controller: 'AdminController'
})
.when('/configs', {
templateURL: '/view/admin/configuracaoAdmin.html',
controller: 'ConfigController'
})
.otherwise({
redirectTo: '/home'
});
}]);


mainAdmin.js (dir: js/controllers/admin/)

app.controller('MainAdmin', function($scope){
$scope.message="MainAdmin"
});


inicioAdmin.html (dir: view/admin/)

<h1>{{ message }}</h1>


Am I missing something? Thanks.

Sander Elias

unread,
Jul 13, 2015, 1:59:30 AM7/13/15
to ang...@googlegroups.com
Hi Oswaldo,

Yes, you missed the point that templateUrl, isn't spelled ending in 3 capitals. Upper U lower rl. That should do the trick. Don't slam yourself, I was used to a case insensitive language before JS, It took a quite a long time before I got used to that! :-D

Regards
Sander

Oswaldo Roberto Marques

unread,
Jul 13, 2015, 1:23:20 PM7/13/15
to ang...@googlegroups.com
Hi Sander,

Thank you. It works now! :D

Regards

Oswaldo

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/7eJS4qFrxOQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages