Javascript 从html创建一个指令,该指令按类名应用函数

Javascript 从html创建一个指令,该指令按类名应用函数,javascript,jquery,angularjs,angularjs-directive,Javascript,Jquery,Angularjs,Angularjs Directive,请告诉我如何将这些代码从使用jQuery插件重新编写为与AngularJs一起使用的指令: <div class="fotorama" data-nav="thumbs" data-allowfullscreen="1" data-thumbheight="100" data-thumbwidth="100"> <img src="img/gamer_chick_800x600.jpg" alt="Image Alternative text" title="Gamer


请告诉我如何将这些代码从使用jQuery插件重新编写为与AngularJs一起使用的指令:

<div class="fotorama" data-nav="thumbs" data-allowfullscreen="1" data-thumbheight="100" data-thumbwidth="100">
   <img src="img/gamer_chick_800x600.jpg" alt="Image Alternative text" title="Gamer Chick" />
   <img src="img/amaze_800x600.jpg" alt="Image Alternative text" title="AMaze" />
   <img src="img/urbex_esch_lux_with_laney_and_laaaaag_800x600.jpg" alt="Image Alternative text" title="Urbex Esch/Lux with Laney and Laaaaag" />
   <img src="img/food_is_pride_800x600.jpg" alt="Image Alternative text" title="Food is Pride" />
</div>


在AngularJS中运行应用程序时,此代码将放入“视图”HTML文件中。谢谢。

我为你的问题添加了plunkr。请参考以下链接

代码

主html

<!DOCTYPE html>
<html ng-app="docsIsolationExample">

  <head>

    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>

    <script src="example.js"></script>

  </head>

  <body>
    <div ng-controller="Controller">
  <my-customer ></my-customer>
</div>
  </body>

</html>
您可以使用自定义指令将temple添加到html页面。请参考以下链接了解如何实现自定义指令


希望下面的链接能帮助您,请参考angularjs链接。。谢谢,但是我已经尝试了一些方法,没有一种方法像我期望的那样有效。我的问题是当指令被加载时,它会在HTML内容被ng repeat填充之前呈现HTML文件。所以没有效果运行。你能详细说明你的问题以及你是如何实现的吗?这将有助于我们确定正确的解决方案。最好只使用
ng include
执行指令所需的解决方案来实现模板指令。如此提供
<div class="fotorama" data-nav="thumbs" data-allowfullscreen="1" data-thumbheight="100" data-thumbwidth="100">
   <img src="img/gamer_chick_800x600.jpg" alt="Image Alternative text" title="Gamer Chick" />
   <img src="img/amaze_800x600.jpg" alt="Image Alternative text" title="AMaze" />
   <img src="img/urbex_esch_lux_with_laney_and_laaaaag_800x600.jpg" alt="Image Alternative text" title="Urbex Esch/Lux with Laney and Laaaaag" />
   <img src="img/food_is_pride_800x600.jpg" alt="Image Alternative text" title="Food is Pride" />
</div>
angular.module('docsIsolationExample', [])
.controller('Controller', ['$scope', function($scope) {
  $scope.naomi = { name: 'Naomi', address: '1600 Amphitheatre' };
  $scope.vojta = { name: 'Vojta', address: '3456 Somewhere Else' };
}])
.directive('myCustomer', function() {
  return {
    restrict: 'E',
    scope: {
      customerInfo: '=info'
    },
    templateUrl: 'my-customer-plus-vojta.html'
  };
});