2014-01-19 54 views
0

我想知道是否有任何約定,如果我想實現twitter引導到我的angularJS應用程序或角度只是不顯眼的twitter引導?AngularJS和Twitter Bootstrap

+0

值得注意的是,角隊有引導作爲其一部分的UI庫:http://angular-ui.github.io/bootstrap/ – gonzofish

回答

2

您需要在引導程序中分別引導bootstrap javascript組件以使其工作。下面是使模態JavaScript插件與角度一起工作的示例。

有一個活躍的社區Angular UI bootstrap它有效地實現了引導JavaScript插件作爲Angular指令。

我覺得,編寫我自己的指令使定製變得簡單,並且不需要在您的web應用程序中使用大量的JavaScript庫文件。

angular.module(app.name).directive('modaldir', function() { 
    return { 
    restrict: 'A', 
    // The linking function will add behavior to the template 
    link: function(scope, element, attrs) { 
     console.log("inside modal"); 
     element.click(function(e) { 
     e.preventDefault(); 
     var href = element.attr('href'); 
     console.log(href); 
     $(href).modal(); 
     }); 
    } 
    }; 
}) 

HTML:

<a data-toggle="modal" href="#myModal" modaldir class="pull-right password-retrieve" >Forgot your password?</a> 
+0

其實一些這個答案中的語句是不正確的:AngularUI團隊不會在指令中包裝Bootstrap的JavaScript,而是將這些JS組件重新實現爲本地AngularJS指令。這與AngularUI方法有很大不同,您不需要包含jQuery或Bootstrap的JavaScript - 您只需要Bootstrap的CSS。 –

+0

是的,你是對的。我編輯了我的答案 –