これが私のURLです
ログイン用- http://localhost/ang/#/login
ダッシュボードの場合- http://localhost/ang/#/dashboard
これがbodyタグの私のhtmlです
これが現在のURLであるhttp://localhost/ang/#/login
場合、本文にはclass="login-layout"
タグが必要です。
<body ng-cloak="" class="login-layout>
そうでなければそれは持っているべきです
<body ng-cloak="" class="no-skin">
私はここで言ったように私がURLを取ることができないことによってphpでこれをやろう#
としました
これはAngularJS自体で行うことができますか?
更新:
私はAngularJSでこれをやろうとしました
コントローラーから私は後にURLを取得できます #
var nextUrl = next.$$route.originalPath;
しかし、どうすればクラス名を変更できますか。
私はプロジェクトでこれを行う必要があり、これが私がそれを達成した方法です:
私のメインアプリコントローラーの中には:
// Inject the $location service in your controller
// so it is available to be used and assigned to $scope
.controller('AppCtrl', ["$scope", "$location",...
// this_route() will be the variable you can use
// inside angular templates to retrieve the classname
// use it like class="{{this_route}}-layout"
// this will give you -> e.g. class="dashboard-layout"
$scope.this_route = function(){
return $location.path().replace('/', '');
};
これにより、スコープの現在のルート名が公開されます。
次に、私のbodyタグは単に次のようになります。
<body ng-controller="AppCtrl" class="{{this_route()}}-view" ng-cloak>
同様に、これを$ stateで使用して、を読み取り、$state.current.url
スコープに割り当てることができます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加