【发布时间】:2016-07-22 12:38:44
【问题描述】:
我在 data-ng-class 上的 div 上做了一个条件语句,我想以某种方式将此范围添加到控制器并指定 url 何时为 /vegetarian 以应用类“egg”,我手动更改我想要的 url要应用“培根”类,但它不起作用,我哪里出错了?
html:
<div data-ng-class="{'egg': isVeggie, 'bacon': !isVeggie }">
Text here
</div>
控制器:
app.controller('foodCtrl', function ($scope, $location) {
$scope.location = $location;
$scope.isVeggie = false;
$scope.isVeggie = function() {
if(isVeggie === $location.path('/vegetarian')) {
return true;
}
}
});
这不起作用。当我输入 /vegetarian 时,正在应用鸡蛋类,但是当我将 url 更改为 /breakfast 之类的其他内容时,“鸡蛋”类仍然存在。我怎样才能使这项工作? 谢谢
【问题讨论】:
标签: angularjs url controller ng-class route-provider