javascript - Variable in isActive method in ng-class, angularjs -


i have html file used directive in angular scope.course defined in .js file. in code below ng-href="courses/{{course.url}}" works nicely , gives link of "courses/myurl"

but when putting in variable in isactive method in ng-class doesnt show, if cant access here.

<li ng-class={active: isactive('/courses/{{course.url}}')}><a ng-href="courses/{{course.url}}">overview</a></li> 

my isactive method looks this:

scope.isactive = function(route){      console.log(route);     return route === $location.path();  } 

but logs "/courses/" without else

how can put in course.url isactive method?

try this:

var mod = angular.module('myapp', []);  mod.controller('mycontroller', function($scope, $location) {    $scope.course = {      url: 'myurl'    };        $scope.isactive = function(route){      return route === '/courses/myurl';      }  });
.active {    color: green;    }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>  <div ng-app="myapp" ng-controller="mycontroller">    <div ng-class="{'active':  isactive('/courses/' + course.url) }"><a ng-href="courses/{{course.url}}">overview</a>    </div>  </div>


Comments