如何在猫头鹰旋转木马的角度制作指令? [英] how to make directive in angular of owl carousel?

查看:82
本文介绍了如何在猫头鹰旋转木马的角度制作指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能告诉我如何在角度js中制作dirctive。我需要在js中使用owl carousel插件,就像我在jqm小提琴中所做的那样 http://jsfiddle.net/ezanker/o9foej5L/1/
。我需要在角度使用指令中做同样的事情,请你告诉我如何实现这个使用指令
http://plnkr.co/edit/4ySYwsqrBKUJUj6MwoRY?p=catalogue

can you please tell me how to make dirctive in angular js .I need to use owl carousel plugin in js as I did in jqm fiddle http://jsfiddle.net/ezanker/o9foej5L/1/ .I need to make same thing in angular using directive can you please tell me how I will implement this using directive http://plnkr.co/edit/4ySYwsqrBKUJUj6MwoRY?p=catalogue

<!DOCTYPE html>
<html>

  <head>
    <link data-require="bootstrap-css@3.x" data-semver="3.2.0" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
      <link data-require="bootstrap-css@3.x" data-semver="3.2.0" rel="stylesheet" href="http://www.owlgraphic.com/owlcarousel/owl-carousel/owl.carousel.css" />
     <link data-require="bootstrap-css@3.x" data-semver="3.2.0" rel="stylesheet" href="   http://www.owlgraphic.com/owlcarousel/owl-carousel/owl.theme.css" />

    <script data-require="angular.js@*" data-semver="1.3.0-beta.5" src="https://code.angularjs.org/1.3.0-beta.5/angular.js"></script>
    <script data-require="ui-bootstrap@0.10.0" data-semver="0.10.0" src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.10.0.js"></script>
    <link href="style.css" rel="stylesheet" />
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

    <script src="script.js"></script>
    <script src="http://www.owlgraphic.com/owlcarousel/owl-carousel/owl.carousel.js"></script>
  </head>

  <body>
   <div id="owl-demo">
 <div class="item"><p>one</p></div>
<div class="item"><p>two</p></div>
<div class="item"><p>three</p></div>
<div class="item"><p>four</p></div>
</div>
  </body>

</html>


推荐答案

你可以使用这样的指令:

You can use a directive like this:

app.directive('owlCarousel', function() {
  return {
    restrict: 'A',
    scope: {
      owlOptions: '='
    },
    link: function(scope, element, attrs) {
      $(element).owlCarousel(scope.owlOptions);
    }
  };
});

并在HTML上将其添加为属性:

And on the HTML add it as an attribute:

<div owl-carousel owl-options="owlOptions">
  ...
</div>

演示

Demo

这篇关于如何在猫头鹰旋转木马的角度制作指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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