LoginSignup
1
1

More than 5 years have passed since last update.

$location.pathを使ってactiveなメニューにクラスを追加する

Last updated at Posted at 2015-05-30
<ul>
    <li ng-class='{ active : isActive("/menu01") }'>
        <a href='#/menu01'>Menu 1</a>
    </li>
    <li  ng-class='{ active : isActive("/menu02") }'>
        <a href='#/menu02'>Menu 2</a>
    </li>
</ul>
$scope.isActive = function(path){
    return path === $location.path();
}

参考


$locationの使用について | AngularJS 1.2 日本語リファレンス |
Angular js add class to active element

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1