gpt4 book ai didi

javascript - $routeProvider 与 templateURL 不工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:44:47 25 4
gpt4 key购买 nike

我在 AngularJS 中使用 $routeProvider 和 templateURl,我的问题是没有任何反应,开发工具(Chrome 或 Firefox)的控制台和网络选项卡上没有任何显示。如果我使用模板,它就可以工作。

下面是 hmtl 和 js 文件。

ma​​inPainelAdmin.html(目录: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>

<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(目录:js/)

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

menuPainelAdmin.js(目录: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: 'inicioAdmin.html',
controller: 'MainAdmin'
})
.when('/admin', {
templateURL: 'administracaoAdmin.html'
})
.when('/configs', {
templateURL: 'configuracaoAdmin.html'
})
.otherwise({
redirectTo: '/home'
});
}]);

ma​​inAdmin.js(目录:js/controllers/admin/)

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

inicioAdmin.html(目录:view/admin/)

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

我错过了什么吗?谢谢。

最佳答案

templateURL 在你的路由配置中应该是 templateUrl。
{templateUrl: 'some/page.html'}

关于javascript - $routeProvider 与 templateURL 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31370946/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com