angularjs 中 $state.includes 的用途是什么?
what is the purpose of $state.includes in angularjs?
我是 angularjs 的新手,我很少混淆 ng-include 和 $state.includes.谁能告诉我为什么我们使用 $state.includes 而不是 ng-include 指令?
它们是完全不同的东西。喜欢 Java 和 Java 脚本? :-)
$state.includes
is a way to see if the current state is or is child of the provided state while using ui-router
.
$state.includes(stateName [, params])
Returns Boolean
A method to determine if the current active state is equal to or is the child of the state stateName
. If any params
are passed then they will be tested for a match as well. Not all the parameters need to be passed, just the ones you'd like to test for equality.
其中,ng-include
是一个 AngularJS 指令,用于获取、编译和包含外部 HTML 片段。
尽管如此,您还是应该在询问之前尝试在 Internet 上阅读它们!
假设您有一个带有一些子菜单的父菜单。对于每个子菜单,您都有类似这样的内容来添加活动 class:
ui-sref-active="active"
但是当您导航到 每个 子菜单时,您还需要为父菜单添加活动 class 您可以使用 states.Then ui-router
包括。
<li ng-class="{ active: state.includes('parentState') }">
注意:您必须将此添加到您的控制器:
$scope.state = $state;
关于ng-include,与$state.include无关。它将外部 html 编译到指令中。
我是 angularjs 的新手,我很少混淆 ng-include 和 $state.includes.谁能告诉我为什么我们使用 $state.includes 而不是 ng-include 指令?
它们是完全不同的东西。喜欢 Java 和 Java 脚本? :-)
$state.includes
is a way to see if the current state is or is child of the provided state while usingui-router
.$state.includes(stateName [, params])
Returns Boolean
A method to determine if the current active state is equal to or is the child of the state
stateName
. If anyparams
are passed then they will be tested for a match as well. Not all the parameters need to be passed, just the ones you'd like to test for equality.其中,
ng-include
是一个 AngularJS 指令,用于获取、编译和包含外部 HTML 片段。
尽管如此,您还是应该在询问之前尝试在 Internet 上阅读它们!
假设您有一个带有一些子菜单的父菜单。对于每个子菜单,您都有类似这样的内容来添加活动 class:
ui-sref-active="active"
但是当您导航到 每个 子菜单时,您还需要为父菜单添加活动 class 您可以使用 states.Then ui-router
包括。
<li ng-class="{ active: state.includes('parentState') }">
注意:您必须将此添加到您的控制器:
$scope.state = $state;
关于ng-include,与$state.include无关。它将外部 html 编译到指令中。