• Angular使用$compile为从Ajax加载的HTML绑定ng-click事件


    这是一个Angular使用$compile为从Ajax加载的HTML绑定ng-click事件的实现方式,由于近期忙碌,就先放代码。代码如下:

    <table data-ng-table="tableParams" class="table table-bordered table-hover " style="border-collapse:collapse" data-ng-init="host.editSave = false">
        <tr id="newTransaction"></tr>
        <tr data-ng-repeat="host in hosts|filter:search:strict">
            <td class="hostTableCols" data-ng-hide="host.editSave">{{host.hostCd}}</td>
            <td class="hostTableCols" data-ng-hide="host.editSave">{{host.hostName}}</td>
        </tr>
    </table>
    

    js:

    var app = angular.module('my-app', [], function () {
    
    })
    
    app.controller('AppController', function ($scope, $compile) {
    
        var $el = $('<td contenteditable><input type="text" class="editBox" value=""/></td>' +
            '<td contenteditable><input type="text" class="editBox" value=""/></td>' +
            '<td>' +
            '<span>' +
            '<button id="createHost" class="btn btn-mini btn-success" data-ng-click="create()"><b>Create</b></button>' +
            '</span>' +
            '</td>').appendTo('#newTransaction');
        $compile($el)($scope);
        
        $scope.create = function(){
            console.log('clicked')
        }
    })
    

      PS:如果有写错的地方,欢迎指出,谢谢。

  • 相关阅读:
    UIView与CALayer的区别,很详细
    IOS图标尺寸一览
    iOS开发之WebView
    iOS开发之版本控制(SVN)
    IOS 多个ImageView图片层叠透明区域点击事件穿透
    UIButton
    UISwitch
    cocoapods_第二篇
    UIView
    IOS开发中 RunLoop,RunTime
  • 原文地址:https://www.cnblogs.com/heroine/p/6086664.html
Copyright © 2020-2023  润新知