/** * Created by NICK on 15/10/13. * email:nick121212@126.com * qq:289412378 * copyright NICK */ import ref = require('ref'); import common = require('common/common/controller/base_material_controller'); import userModel = require('common/models/passport/user_model'); export class Directive extends common.BaseController { public static _name:string = "dyCompile"; public static directive:Array = ['$rootScope', '$compile', ($rootScope, $compile) => { var directive:ng.IDirective = { replace: true, restrict: 'EA', scope: { item: '=', $index: '=', query: '=' } }; directive.link = (scope, elm, iAttrs)=> { var DUMMY_SCOPE = { $destroy: angular.noop }, root = elm, childScope, destroyChildScope = function () { (childScope || DUMMY_SCOPE).$destroy(); }; iAttrs.$observe("html", function (html:string) { var content; if (html) { destroyChildScope(); childScope = scope.$new(false); childScope.item = scope['item']; childScope.$index = scope['$index']; childScope.query = scope['query']; if (html.search('<') == 0) { content = $compile(html)(childScope); root.replaceWith(content); root = content; } else { content = childScope.$eval(html); root.text(content); } } scope.$on("$destroy", destroyChildScope); }); }; return directive; }]; }