angularjs - AngularJS 中 $state.includes 的用途是什么?

标签 angularjs angular-ui-router state angularjs-ng-include

我是 angularjs 的新手,我对 ng-include$state.includes 之间没有什么混淆。谁能告诉我为什么我们使用 $state.includes 而不是 ng-include 指令?

最佳答案

假设您有一个带有一些子菜单的父菜单。对于每个子菜单,您都有类似这样的内容来添加事件类:

ui-sref-active="active"

但是当您导航到每个子状态时,您还需要为父菜单添加事件类。然后您可以使用ui-router包含。

<li ng-class="{ active: state.includes('parentState') }">

注意:您必须将其添加到 Controller 中:

$scope.state = $state;

关于ng-include,与$state.include无关。它将外部 html 编译到指令中。

关于angularjs - AngularJS 中 $state.includes 的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43511217/

相关文章:

javascript - 如何可靠地将 HTML 转换为 PDF

angularjs - 从输入将数组发布到数据库

angularjs - 在模板中访问 $state

javascript - 1 个模块的 ui-view 从另一个模块复制内容

javascript - 如何在 $scope.$on 中停止方法执行直到上传结束

AngularJS:在哪里存储与指令相关的 CSS?

javascript - ionic 侧菜单中的异步工厂

javascript - 如何根据AJAX调用设置ReduxReducer的初始状态?

javascript - 在 Redux 中使用状态对象(基本)

Redux:组合关系需要状态规范化吗?