【问题标题】:Angular JS: ng-switch not workingAngular JS:ng-switch 不工作
【发布时间】:2014-11-10 04:34:02
【问题描述】:

我正在尝试在我的应用程序中使用 ng-switch。

In Routing configuration :

when('/Test/:TestName/formEditor/:openedFrom', {
        templateUrl: 'Testing.html',
        controller: 'TestCtrl'
    })

在我的 HTML 中

  <div ng-switch="openedFrom">
    <ul class="breadcrumb" ng-switch-when="fromTab1">
        <li><a href="#/solutions" id="act_
   </ul>
   <ul class="breadcrumb"  ng-switch-when="fromTab2" >
         <li><a href="#/abc">Visitors</a></li>
   </ul>
  </div>

我通过 Openedfrom 的方式是

  <a class="btn btn-primary" href="#/Test/{{TestName}}/formEditor/fromTab1">Tab 1</a>

  <a class="btn btn-primary" href="#/Test/{{TestName}}/formEditor/fromTab2">Tab 2</a>

根本不渲染面包屑。 一旦我删除 ng-switch 一切似乎都可以正常工作。有人可以建议吗?

【问题讨论】:

  • 您是否将您的openedFrom附加到范围?比如控制器中的$scope.openedFrom = $routeParams.openedFrom

标签: angularjs-directive ng-switch


【解决方案1】:

这是因为您使用 `ng repeat` 和 `ng switch` 渲染 div。您可以通过 `ng-if` 使用。

<div>
   <ul class="breadcrumb" ng-if="openedFrom=='fromTab1'">
    <li><a href="#/solutions">Solutions</a></li>
   </ul>
   <ul class="breadcrumb"  ng-if="openedFrom=='fromTab2'" >
      <li><a href="#/abc">Visitors</a></li>
   </ul>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多