我正在开发一个网络应用,并且 routeProvider 可以在配置的视图之间导航:
config.$inject = ['$routeProvider', '$locationProvider'];
function config($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
controller: 'HomeController',
templateUrl: 'home/home.html',
controllerAs: 'vm'
})
.when('/login', {
controller: 'LoginController',
templateUrl: 'login/login.html',
controllerAs: 'vm'
})
.when('/register', {
controller: 'RegisterController',
templateUrl: 'signUp/register.html',
controllerAs: 'vm'
})
**.when('/sitelocator', {
templateUrl: 'sitelocator/sitemap.html',
})**
.otherwise({redirectTo: '/login'});
}
“/ sitelocator”我有一个包含地图的HTML文件(API谷歌地图) 而且我不需要控制器。 问题是只有 templateUrl 页面无法正确加载,我怎么解决? 感谢。
修改
function initialize() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(22.344, 114.048),
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true,
zoomControl: true
});
var polyOptions = {
strokeWeight: 0,
fillOpacity: 0.45,
editable: true
};
// Creates a drawing manager attached to the map that allows the user to draw
// markers, lines, and shapes.
drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.POLYGON,
markerOptions: {
draggable: true
},
polylineOptions: {
editable: true
},
rectangleOptions: polyOptions,
circleOptions: polyOptions,
polygonOptions: polyOptions,
map: map
});
google.maps.event.addListener(drawingManager, 'overlaycomplete', function(e) {
if (e.type != google.maps.drawing.OverlayType.MARKER) {
// Switch back to non-drawing mode after drawing a shape.
drawingManager.setDrawingMode(null);
// Add an event listener that selects the newly-drawn shape when the user
// mouses down on it.
var newShape = e.overlay;
newShape.type = e.type;
google.maps.event.addListener(newShape, 'click', function() {
setSelection(newShape);
});
setSelection(newShape);
}
});
// Clear the current selection when the drawing mode is changed, or when the
// map is clicked.
google.maps.event.addListener(drawingManager, 'drawingmode_changed', clearSelection);
google.maps.event.addListener(map, 'click', clearSelection);
google.maps.event.addDomListener(document.getElementById('delete-button'), 'click', deleteSelectedShape);
buildColorPalette();
}
google.maps.event.addDomListener(window, 'load', initialize);
答案 0 :(得分:0)
Angular Router允许不带控制器的视图。
http://jsbin.com/wuxuwuxiga/1/edit?html,js,console,output
function config($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
template: 'hi'
});
}
angular.module('app', ['ngRoute'])
.config(config);
可能会出现许多问题,其中一个问题可能是你没有在路线上找到正确的道路。您的href
值是否以/
为前缀?您的所有状态都是从Web根目录定义的(在大多数情况下应该是这样)。确保您的链接也指向Web根目录。
<!-- Wrong -->
<a href="sitelocator">Site Locator</a>
<!-- Right -->
<a href="/sitelocator">Site Locator</a>
希望有所帮助。