zoukankan      html  css  js  c++  java
  • AngularJS $compile动态生成html

    angular.module('app')
        .directive('compile', function ($compile) {
            return function (scope, element, attrs) {
                scope.$watch(
                  function (scope) {
                       
                      return scope.$eval(attrs.compile);
                  },
                  function (value) {
                      element.html(value);
                      $compile(element.contents())(scope);
                  }
                );
            };
        });
    

     

    <div ng-app="app" ng-controller="SampleCtrl" class="container">
         <div ng-repeat="item in items">
             {{item.name}}<br />
             <div compile="item.tempatle"></div>         
         </div>   
     </div>
    <script>
           angular
               .module('app')
               .controller('SampleCtrl', function ($scope, $filter) {
     
                   $scope.open = function () {
                       alert("ddd");
                   }
                   $scope.items = [
                       { "name": "zhangsan", tempatle: '<i class="searchicon fa fa-search"   ng-click="open()" style="color:#5db2ff;cursor:pointer;">点击</i>' },
                       { "name": "lisi", tempatle: '<i class="searchicon fa fa-search"   ng-click="open()" style="color:#5db2ff;cursor:pointer;">点击</i>' },
                       { "name": "wangwu", tempatle: '<i class="searchicon fa fa-search"   ng-click="open()" style="color:#5db2ff;cursor:pointer;">点击</i>' }]
     
               });
       </script>

     

  • 相关阅读:
    处理器及其调度
    java面向对象
    操作系统概述
    mysql 基础操作
    java集合类详解
    java数组
    java方法
    Python—进程间通信
    Python—TCP的黏包问题以及UDP的分片问题
    Python—网络通信编程之tcp非阻塞通信(socketserver)
  • 原文地址:https://www.cnblogs.com/guozhe/p/7428016.html
Copyright © 2011-2022 走看看