标签:
<html ng-app="compile"> <head> <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> </head> <body> <div ng-controller="compileCtrl"> <ts-s> </ts-s> </div> <script type="text/javascript"> var app = angular.module("compile", []); app.controller("compileCtrl", function($scope){ $scope.updateModuleInfo = function( module ){ console.log("module : " + module); } }); app.directive(‘tsS‘, function($compile) { return { //template:"<input type=‘text‘ ng=model=‘sampleData‘/> {{sampleData}} <br/>" link: function(scope, element, atts, controller) { var module = { id : "11", name : "john" } var markup = "<input type=‘text‘ ng-model=‘sampleData‘ ng-change=‘updateModuleInfo(module)‘/> {{sampleData}} <br/>"; element.html(markup); scope.module = module;//向scope中插入module对象 $compile(element.contents())(scope); } }; }); </script> </body> </html>
em:
scope.module = module;//向scope中插入module对象
renderRow : function(nRow, aData, iDataIndex, anHidden){ var link = $compile(‘<a href="" ng-click="updateModuleInfo(aData)> 编辑 </a>‘ ); var scope = $scope.$new(false);//新建子作用域 var node = link(scope); scope.aData = aData;//向scope中插入aData对象 if (true) { $(--).html(node) } }
标签:
原文地址:http://www.cnblogs.com/zyjzz/p/5744640.html