adminという名前のディレクティブを作成しました。このURLは、ベースURLにadminという文字列が含まれている場合に表示し、URLパスに応じて表示されます。異なる内容を表示する
ので、ユーザはに移動した場合admin.example.com彼らはちょうどexample.comをに行けば、彼らはディレクティブのビューが表示されます、彼らはそれを表示されません。
私はextentJSアプリケーションを最初に読み込んだときに機能しますが、別のページをクリックして別のビューやルートを読み込んだ場合は機能しません。
これが私の基本的なアプリです:私はアプリ内で異なるルートをクリックして、ページを更新せずにページを変更しない場合は、ページを更新する際に問題がadminCtrl.urlPath = $location.url();
更新のみである
/* Define the `app` module */
var app = angular.module('app', ['ngRoute', 'ngTouch', 'ngAnimate', 'ui.bootstrap', 'ngSanitize']); // TODO: 'ngAnimate', 'ui.bootstrap'
app.config(['$routeProvider','$locationProvider', function($routeProvider, $locationProvider){
$routeProvider
.when('/', {
class: 'home-page',
title: 'Home',
templateUrl: '/app/static/home.html',
controller: 'mainController as mainCtrl'
})
.when('/about', {
class: 'about-page',
title: 'About',
templateUrl: '/app/static/about.html',
controller: 'mainController as mainCtrl'
})
.when('/news/id-:newsId', {
class: 'news-page',
title: 'News',
templateUrl: 'app/components/news/details/newsDetailsView.html',
controller: 'newsDetailsController as newsDCtrl'
})
.otherwise({
class: 'page-not-found',
title: '404 Page Not Found',
templateUrl: '/app/static/404.html',
controller: 'mainController as mainCtrl'
});
// use the HTML5 History API
$locationProvider.html5Mode(true);
}]);
app.run(['$rootScope', function($rootScope) {
$rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
$rootScope.class = current.$$route.class;
$rootScope.title = current.$$route.title;
$rootScope.description = current.$$route.description;
});
}]);
app.controller('adminController', ['$location', function ($location) {
var adminCtrl = this;
adminCtrl.isAdmin = $location.host().includes('admin.example') ? true : false;
adminCtrl.urlPath = $location.url();
}])
app.directive('admin', [function(){
return {
restrict: 'E',
templateUrl: 'app/components/admin-links/adminView.html',
transclude: true,
replace: true,
controller: 'adminController as adminCtrl'
};
}]);
。
ユーザーがページを更新せずにさまざまなビュー/ルートをナビゲートしたときに、この値を更新するにはどうすればよいですか?
へ
変更
、私はHTMLで意味ですか? –