栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Google Pagedown AngularJS指令

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Google Pagedown AngularJS指令

这是一个工作链接:

http://cssdeck.com/labs/qebukp9k

更新

  • 我做了一些优化。
  • 我使用ngModel。$ formatters!不需要另外的手表。
  • 我使用$ timeout然后使用scope。$ apply来避免$ digest进行中的错误。

Angular.js和性能

  • 如果您提高了性能,则可能是您的应用程序使用了过多的$ watch / $ on。
  • 以我的经验,使用第三方库可能会导致各种无效/内存泄漏行为,主要是因为未考虑到angular / SPA的实现。
  • 我能够对某些库进行一些智能集成,但是有些库并不适合Angle的世界。
  • 如果您的应用程序 必须 显示1000多个问题,则可能应该从编写自定义中继器开始,并且更喜欢动态DOM插入。
  • 除非您愿意编写一些智能的低级内容,否则Angular.js在大量数据绑定中的性能将不佳(当您知道如何做时,这实际上很有趣!)。
  • 同样,更喜欢分页!正如Misko Hevery所说: “您不能在一个页面上向一个人真正显示超过2000条信息。除此之外,还真是糟糕的UI,而且人也无法对其进行处理”。
  • 我非常乐意为您提供帮助,但是首先让我显示代码(与我联系)。

解:

var app = angular.module('App', []);app.directive('pagedownAdmin', function ($compile, $timeout) {    var nextId = 0;    var converter = Markdown.getSanitizingConverter();    converter.hooks.chain("preBlockGamut", function (text, rbg) {        return text.replace(/^ {0,3}""" *n((?:.*?n)+?) {0,3}""" *$/gm, function (whole, inner) { return "<blockquote>" + rbg(inner) + "</blockquote>n";        });    });    return {        require: 'ngModel',        replace: true,        template: '<div ></div>',        link: function (scope, iElement, attrs, ngModel) { var editorUniqueId; if (attrs.id == null) {     editorUniqueId = nextId++; } else {     editorUniqueId = attrs.id; } var newElement = $compile(     '<div>' +        '<div >' +'<div id="wmd-button-bar-' + editorUniqueId + '"></div>' +'<textarea  id="wmd-input-' + editorUniqueId + '">' +'</textarea>' +        '</div>' +        '<div id="wmd-preview-' + editorUniqueId + '" ></div>' +     '</div>')(scope); iElement.html(newElement); var help = function () {     alert("There is no help"); } var editor = new Markdown.Editor(converter, "-" + editorUniqueId, {     handler: help }); var $wmdInput = iElement.find('#wmd-input-' + editorUniqueId); var init = false; editor.hooks.chain("onPreviewRefresh", function () {   var val = $wmdInput.val();   if (init && val !== ngModel.$modelValue ) {     $timeout(function(){       scope.$apply(function(){         ngModel.$setViewValue(val);         ngModel.$render();       });     });   }    }); ngModel.$formatters.push(function(value){   init = true;   $wmdInput.val(value);   editor.refreshPreview();   return value; }); editor.run();        }    }});


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/633280.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号