我怎么能选择从外部控制器卡 [英] how can I select a tab from outside controller

查看:199
本文介绍了我怎么能选择从外部控制器卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用标签(ui.bootstrap.tabs)控制\\指令所描述的此处。该控件创建它自己的控制器,它集活动标签:

I'm using Tabs (ui.bootstrap.tabs) control\directive described here. The control creates it's own controller which sets active tab:

.controller('TabsetController', ['$scope', function TabsetCtrl($scope) {
  var ctrl = this,
      tabs = ctrl.tabs = $scope.tabs = [];

  ctrl.select = function(selectedTab) {
    angular.forEach(tabs, function(tab) {
      if (tab.active && tab !== selectedTab) {
        tab.active = false;
        tab.onDeselect();
      }
    });
    selectedTab.active = true;
    selectedTab.onSelect();
  };

他们点击后

标签集子标签控件(子元素)可以触发家长的选择功能。

Tabset child tab controls (child elements) can trigger parent's select function when clicked on them.

.directive('tab', ['$parse', function($parse) {
  return {
    require: '^tabset',
    scope: {
      onSelect: '&select',

我有我的定制控制器向上这就需要触发DOM 选择 TabsetController 函数来设置一个选项卡活跃。我读过,我可以用赛事转播,但我不能修改 TabsetController 来事件监听器绑定所以这似乎不是一种可行的选择。有什么建议?

I have my custom controller upwards the DOM which needs to trigger select function on TabsetController to set first tab active. I've read that I could use event broadcasting but I can't modify TabsetController to bind event listener so this doesn't seem to be a viable option. Any suggestions?

编辑:

请参阅Plunker为了更好的理解 - 。这里

Please see Plunker for better understanding - here.

推荐答案

您可以在母控制器内声明scope属性,这将是在孩子的控制器访问。
请参阅: AngularJS - 访问子作用域

You can declare a scope attribute within the "parent" controller and it will be accessible in the child controller. see: AngularJS - Access to child scope

由于TabsetController设定一个子DOM元素而MainController设置父元素上,则可以在MainController定义和操作$ scope.tabs,并可以看到和INTE $ P $在TabsetController PTED

Because TabsetController is set on a child DOM element while the MainController is set on a parent element, you can define and manipulate $scope.tabs in the MainController, and it will be seen and intepreted in TabsetController.

这篇关于我怎么能选择从外部控制器卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆