我尝试在网站上删除网址中的hastag,但我并不确切知道如何...
我在互联网上进行了研究,我发现在我的控制器中插入位置提供程序是必要的,但是...在哪里?
这是我的控制器代码:
'use strict';
(function() {
var app = angular.module('store', ['store-products']);
app.controller('StoreController', ['$log', function($log) {
this.products = gems;
$log.info('Dependency Info');
}]);
app.controller('PanelController', function() {
this.tab = 1;
this.selectTab = function(setTab) {
this.tab = setTab;
};
this.isSelected = function(checkTab) {
return this.tab === checkTab;
};
});
app.controller('ReviewController', function() {
this.review = {};
this.addReview = function(product) {
product.reviews.push(this.review);
this.review = {};
};
});
var gems = [
{
name: 'Dodecahedron',
price: 2.95,
description: 'Dodecahedron description...',
images: [
{
full: 'http://courseware.codeschool.com.s3.amazonaws.com/shaping-up-with-angular-js/images/gem-01.gif'
}
],
canPurchase: true,
soldOut: false,
reviews: [
{
stars: 5,
body: 'Awesome website',
author: 'user1@schimbatot'
},
{
stars: 4,
body: 'Good!',
author: 'user2@schimbatot'
}
]
},
];
})();
和模块代码:
(function() {
var app = angular.module('store-products', []);
app.directive('productTitle', function () {
return {
restrict: 'E',
templateUrl: 'product-title.html'
};
});
})();
另外,要找到在我的索引中添加<base href="/">
的必要条件。
但是,在哪里插入$ locationProvider命令是必要的? ($locationProvider.html5Mode(true);
)
编辑,这是我的索引来自页面:
<!doctype html>
<html ng-app="store">
<head>
<title>AngularJS App</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css" />
<link rel="stylesheet" href="application.css" />
<script src="app.js"></script>
<base href="/">
</head>
<body>
<h1>AngularJS App</h1>
<div class="container" ng-controller="StoreController as store">
<h1>AngularJS App</h1>
<div ng-repeat="product in store.products">
<h3>
<product-title></product-title>
</h3>
<section ng-controller="PanelController as panel">
<ul class="nav nav-pills">
<li ng-class="{active:panel.isSelected(3)}"><a href="#" ng-click="panel.selectTab(3)">Reviews</a></li>
</ul>
<div class="panel" ng-show="panel.isSelected(1)">
<h4>Description</h4>
<blockquote>Product description...</blockquote>
</div>
<div class="panel" ng-show="panel.isSelected(2)">
<h4>Specifications</h4>
<blockquote>None yet</blockquote>
</div>
<div class="panel" ng-show="panel.isSelected(3)">
<h4>Reviews</h4>
<blockquote ng-repeat="review in product.reviews">
<b>Stars: {{review.stars}}</b>
{{review.body}}
<cite>by: {{review.author}}</cite>
</blockquote>
<form name="reviewForm" ng-controller="ReviewController as reviewCtrl" ng-submit="reviewForm.$valid && reviewCtrl.addReview(product)" novalidate>
<blockquote>
<b>Stars: {{reviewCtrl.review.stars}}</b>
{{reviewCtrl.review.body}}
<cite>by: {{reviewCtrl.review.author}}</cite>
</blockquote>
<select ng-model="reviewCtrl.review.stars" required>
<option value="1">1 star</option>
<option value="2">2 star</option>
<option value="3">3 star</option>
<option value="4">4 star</option>
<option value="5">5 star</option>
</select>
<textarea ng-model="reviewCtrl.review.body" required></textarea>
<label>by:</label>
<input ng-model="reviewCtrl.review.author" type="email" required />
<input class="btn" type="submit" value="Submit" />
</form>
</div>
</section>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.4/angular.min.js"></script>
<script src="products.js"></script>
<script src="app.js"></script>
</div>
</body>
</html>
谢谢你的帮助!
答案 0 :(得分:2)
您需要在配置中指定html5模式,如下所示
var app = angular.module('store', ['store-products'])
.config(['$locationProvider', function($locationProvider) {
$locationProvider.html5Mode(true);
}]);
阅读有关hashbang模式和html5模式的更多信息 [这里](https://docs.angularjs.org/guide/ $ location)
答案 1 :(得分:1)
你不能这样做.... 实际上很少有这个步骤
您可以参考以下视频,它将为您提供清晰的图片
https://www.youtube.com/watch?v=XsRugDQaGOo&ab_channel=kudvenkat