Javascript 在同一域内分离ng路由
我有一个主网站,它使用index.html和侧导航,并使用ng视图将内容加载到其中。那很好。目前,我有一个event.html页面,它是一个完全不同的布局,需要基于单独的ng应用程序进行路由。当前,我的url如下所示:Javascript 在同一域内分离ng路由,javascript,angularjs,ngroute,angularjs-ng-route,Javascript,Angularjs,Ngroute,Angularjs Ng Route,我有一个主网站,它使用index.html和侧导航,并使用ng视图将内容加载到其中。那很好。目前,我有一个event.html页面,它是一个完全不同的布局,需要基于单独的ng应用程序进行路由。当前,我的url如下所示: var app = angular.module('event', ['ngRoute']); app.controller('RouteController', ['$scope', '$route', '$routeParams', '$location', functio
var app = angular.module('event', ['ngRoute']);
app.controller('RouteController', ['$scope', '$route', '$routeParams', '$location', function($scope, $route, $routeParams, $location) {
$scope.$route = $route;
$scope.$location = $location;
$scope.$routeParams = $routeParams;
}]);
app.controller('LandingController', ['$scope', '$rootScope', '$routeParams', '$timeout', '$http', function($scope, $rootScope, $routeParams, $timeout, $http) {
$rootScope.title = 'Event'; // Page name in browser bar
$scope.$routeParams = $routeParams;
$http.get("../json/headshots.json").success(function(data) {
$scope.headshots = data;
// So we give the DOM a second to load the data
setTimeout(function() {
$('.modal-trigger').leanModal();
}, 1500);
});
// Always make sure we are looking at the top of the page
$('html, body').animate({
scrollTop: 0
}, 'slow');
}]);
app.controller('InstructorsController', ['$scope', '$rootScope', '$routeParams', '$timeout', '$http', function($scope, $rootScope, $routeParams, $timeout, $http) {
$rootScope.title = 'Instructors'; // Page name in browser bar
$scope.$routeParams = $routeParams;
$http.get("../json/instructors.json").success(function(data) {
$scope.headshots = data;
});
// Always make sure we are looking at the top of the page
$('html, body').animate({
scrollTop: 0
}, 'slow');
}]);
app.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: 'pages/event-landing-page.html',
controller: 'LandingController',
})
.when('/instructors', {
templateUrl: 'pages/instructors.html',
controller: 'InstructorsController',
})
.otherwise({
redirectTo: '/'
});
// Leave this false so people can access pages without having
// to go to cwru.edu/swingclub first.
$locationProvider.html5Mode(false);
});
name of organization.com我不确定我是否理解你的问题,但你似乎想要一条路线的子路线。您似乎正在使用路由器ui,所以我不知道它是如何使用的,但是,您可以为给定的路由执行如下子例程:
.when('/hello',{
templateUrl : 'pages/hello.html',
controller : 'helloController'
})
//route for individual breeder
.when('/hello/:param',{
templateUrl : 'pages/differentTemplate.html',
controller : 'anotherControllerr'
})
路由之后,您的url将类似于#/hello/param
。
在您的第二个控制器中,您可以根据
$location.absURL()
确定您想要去的地方,在那里加载一个特定的模板(如果要快速解决问题,可以使用一堆ng)。类似于,如果a-加载此模板
等等。因此,即使尝试上面的方法,我的问题是这两个单独的部分有不同的nabber(它们确实应该是两个单独的网站,但这很难,因为我们希望活动网站与我们的URL关联)。我尝试执行ngif(“title=='Event')
,尝试切换正在显示的nabber,但最终导致堆栈溢出。所以我还是在想该怎么做。是的,我知道了。谢谢你的回答,它确实有帮助!