简体   繁体   English

AngularJS和JQuery UI选项卡

[英]AngularJS and JQuery UI Tabs

I've seen some samples of tabs with AngularJS, and very few about JQueryUI tabs with AngularJS, so I tried to create two directives to create the tabs container, and the tab items. 我已经看到了一些使用AngularJS的选项卡示例,而很少看到有关使用AngularJS的JQueryUI选项卡的示例,因此我尝试创建两个指令来创建选项卡容器和选项卡项目。

Here is the sample code I've created: http://jsfiddle.net/davidzapata/tvq6w1g9/2/ 这是我创建的示例代码: http : //jsfiddle.net/davidzapata/tvq6w1g9/2/

HTML HTML

<div ng-app="biApp">
    <div ng-controller="MyCtrl">
        <h1>{{greeting}}</h1>
        <jqueryuitabs>
            <jqueryuitab id="tab1" title="Tab 1">Tab 1 content</jqueryuitab>
            <jqueryuitab id="tab2" title="Tab 2">Tab 2 content</jqueryuitab>
            <jqueryuitab id="tab3" title="Tab 3">Tab 3 content</jqueryuitab>
        </jqueryuitabs>
    </div>
</div>

JS JS

var appModule = angular.module('biApp', []);

appModule.controller('MyCtrl', function($scope){
    $scope.greeting = 'Hi!';
});

appModule.directive('jqueryuitabs', function () {
    return {
        restrict: 'E',
        transclude: true,
        template: '<div><ul><li ng-repeat="tab in tabs"><a href="#{{tab.id}}">{{tab.title}}</a></li></ul><ng-transclude></ng-transclude></div>',
        controller: function($scope) {
            console.log('jqueryuitabs Controller');
            $scope.tabs = [];

            this.addTab = function(tab){
                console.log('Add Tab', tab);
                $scope.tabs.push(tab);
            }
        },
        link: function(scope, elm, attrs) {
            console.log('jqueryuitabs link');
            var jqueryElm = $(elm[0]);
            $(jqueryElm).tabs();
        }
    };
});

appModule.directive('jqueryuitab', function () {
    return {
        restrict: 'E',
        require: '^jqueryuitabs',
        transclude: true,
        scope: {
            id: "@",
            title: "@"
        },
        template: '<div id="{{id}}" ng-transclude></div>',
        link: function (scope, element, attrs, tabsCtrl) {
            console.log('Tab link');

            tabsCtrl.addTab(scope);
        }
    };
});

I've never created code before in jsfiddle.net, but that code seems to load the required libraries. 我以前从未在jsfiddle.net中创建代码,但是该代码似乎可以加载所需的库。 Even so, the controller works, the "greeting" model is rendered, but the tabs are not working, and they are not even transcluding the content into the respective elements. 即使这样,控制器仍在工作,呈现了“ greeting”模型,但是选项卡不起作用,并且它们甚至没有将内容转换为相应的元素。

Of course, I'm an new using AngularJS, but I haven't figured out how to solve this problem. 当然,我是使用AngularJS的新手,但是我还没有弄清楚如何解决这个问题。

Thanks you! 谢谢!

Use the ng-transclude on a div in your jqueryuitabs directive: 在您的jqueryuitabs指令中的div上使用ng-transclude

template: '<div><ul><li ng-repeat="tab in tabs"><a href="#{{tab.id}}">{{tab.title}}</a></li></ul><div ng-transclude></div></div>'

See jsfiddle . 参见jsfiddle

Stop the custom implementations and just use http://angular-ui.github.io/bootstrap/ . 停止自定义实现,仅使用http://angular-ui.github.io/bootstrap/即可 Its more efficient and you can proceed to focus on more important tasks 它的效率更高,您可以继续专注于更重要的任务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM