Angularjs 的 class 条件 window.location
Angularjs ng-class condition for window.location
我正在尝试 unset/set css class 在特定路径 url
我尝试编写这段代码,但没有成功
<div ng-class="window.location.toString().includes('ocs')? '' :'icon-home'"></div>
在 chrome 控制台中我看到了这个:
<div ng-class="window.location.toString().includes('ocs')? '' :'icon-home'" class="icon-home"></div>
我需要创建一个新的 angularjs 模块和作用域吗?
当你清除 class 如果位置包含 'ocs',正确的方法应该是这样的:
// in you angularjs controller:
$scope.containesOCS = window.location.toString().includes('ocs');
并且在 html 中:
<div ng-class="{'icon-home': !containesOCS}"></div>
如果您还没有创建 angular 模块或控制器,请先创建。没有
ng-app angular 属性将不起作用。
我正在尝试 unset/set css class 在特定路径 url
我尝试编写这段代码,但没有成功
<div ng-class="window.location.toString().includes('ocs')? '' :'icon-home'"></div>
在 chrome 控制台中我看到了这个:
<div ng-class="window.location.toString().includes('ocs')? '' :'icon-home'" class="icon-home"></div>
我需要创建一个新的 angularjs 模块和作用域吗?
当你清除 class 如果位置包含 'ocs',正确的方法应该是这样的:
// in you angularjs controller:
$scope.containesOCS = window.location.toString().includes('ocs');
并且在 html 中:
<div ng-class="{'icon-home': !containesOCS}"></div>
如果您还没有创建 angular 模块或控制器,请先创建。没有 ng-app angular 属性将不起作用。