几天前我开始学习angular.js。
这不会在angular.html中加载视图。我不确定代码中有什么问题。
angular.html
保存在根文件夹中。 view1.html
和view2.html
位于root/partials
文件夹中。
angular.html
<body ng-app="demoApp">
<div>
<div ng-view></div>
<h2> modules </h2>
</div>
</body>
<script>
var demoApp = angular.module('demoApp', []);
demoApp.config(function($routeProvider){
$routeProvider
.when('/',{
controller: 'SimpleController',
templateUrl: 'angularpartials/view1.html'
})
.when('/view2',{
controller: 'SimpleController',
templateUrl: 'angularpartials/view2.html'
})
.otherwise({redirectTo:'/'});
});
demoApp.controller('SimpleController', function ($scope){
$scope.clients=[
{name:'Dave', city:'NJ'},
{name:'Nupur', city:'WC'},
{name:'Heedy', city:'TX'}];
$scope.addClient = function(){
$scope.clients.push({
name: $scope.newClient.name,
city: $scope.newClient.city
});
};
});
</script>
view1.html
<div>
<input type="text" data-ng-model="filter.name"> {{filter.name | uppercase}}
<h3>view1 </h3>
<ul>
<li data-ng-repeat="client in clients | filter : filter.name | orderBy : 'city' "> {{client.name}}<br> </li>
</ul>
New Client: <input type="text" data-ng-model="newClient.name"><br />
Client City<input type="text" data-ng-model="newClient.city"><br />
<button data-ng-click="addClient()">Add Customer</button><br />
<a href="#/view2">view 2</a>
</div>
view2.html
<div class="container">
<input type="text" data-ng-model="filter.name"> {{filter.name | uppercase}}
<br>
<h3>view 2 </h3>
<ul>
<li data-ng-repeat="client in clients | filter : filter.name | orderBy : 'city' "> {{$scope.client.name}} in {{$scope.client.city}}<br> </li>
</ul>
<a href="#/view1">view 1</a>
</div>
答案 0 :(得分:0)
根据您的问题,您的观点应该是
templateUrl: 'root/partials/view2.html'
和
templateUrl: 'root/partials/view1.html'
分别
答案 1 :(得分:0)
templateUrl:'partials / view1.html'
&安培;
templateUrl:'partials / view2.html'
因为该文件已在根文件夹中。