【问题标题】:declare one controller for each tab为每个选项卡声明一个控制器
【发布时间】:2016-04-19 15:03:20
【问题描述】:

我在一个 html 页面中使用选项卡,我试图为每个选项卡声明一个控制器。

<div class="tab-content">
    <div class="tab-pane active" id="customerInfo">
        @customerList()
    </div>
    <div class="tab-pane" id="communities">
        @communityList()
</div>

对于第一个选项卡,我在“customerList”中声明我的控制器,如下所示:

<div class="block full" ng-controller="customerCtrl">

我在第二个标签上尝试了同样的事情,但没有成功。请帮忙。

【问题讨论】:

  • 这里的代码这么少很难提供帮助,我建议根据您的尝试创建一个 plnkr。
  • 感谢您的重播,我想做的很简单,在第一个选项卡中,我有一个我想使用 customerCtrl 的客户列表,第二个选项卡包含我想使用的社区列表使用另一个控制器:communitiesCtrl
  • 我会考虑使用“controller as”来实现这一点。如果您对此进行搜索,您会发现大量示例。

标签: angularjs twitter-bootstrap restangular


【解决方案1】:

这是可能的,从这里判断,您可以这样做很简单:

<body ng-app="">
<div class="tab-content">
    <div class="tab-pane active" id="customerInfo" ng-controller="customerListcontroller">
        @customerList()
    </div>
    <div class="tab-pane" id="communities" ng-controller="communityListcontroller">
        @communityList()
    </div>
</div>
</body>

你可能做错了几件事:

  • 忘记使用 ng-app="app" 来包装你的控制器
  • 从问题中有一个 div 遗漏。确保代码中不是这种情况
  • 未正确定义控制器。
  • 没有调用HTML文件中包含控制器的文件

这应该是一个小修复。 You can also take a look at this.

【讨论】:

    猜你喜欢
    • 2013-11-22
    • 1970-01-01
    • 2014-01-27
    • 1970-01-01
    • 2012-01-13
    • 1970-01-01
    • 1970-01-01
    • 2012-03-23
    • 2016-02-25
    相关资源
    最近更新 更多