- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下 pagedown 指令。每当我更改/编辑文本区域时,如何将指令设置为脏?
app.directive('pagedown', ['$compile', '$timeout', 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 {
restrict: "E",
scope: {
content: "=",
modal: '=modal'
},
link: function (scope, iElement, attrs) {
var editorUniqueId;
if (attrs.id == null) {
editorUniqueId = nextId++;
} else {
editorUniqueId = attrs.id;
}
var newElement = $compile(
'<div>' +
'<div class="wmd-panel">' +
'<div data-ng-hide="modal.wmdPreview == true" id="wmd-button-bar-' + editorUniqueId + '"></div>' +
'<div>' +
'<textarea data-ng-hide="modal.wmdPreview == true" class="wmd-input" id="wmd-input-' + editorUniqueId + '" ng-model="content" >' +
'</textarea>' +
'</div>' +
'</div>' +
'</div>')(scope)
;
iElement.append(newElement);
var help = angular.isFunction(scope.help) ? scope.help : function () {
alert("Do you need help?");
};
var editor = new Markdown.Editor(converter, "-" + editorUniqueId, {
handler: help
});
var editorElement = angular.element(document.getElementById("wmd-input-" + editorUniqueId));
editor.hooks.chain("onPreviewRefresh", function () {
// wire up changes caused by user interaction with the pagedown controls
// and do within $apply
$timeout(function () {
scope.content = editorElement.val();
});
});
editor.run();
}
}
}]);
<pagedown class="pagedown-admin"
modal="ahs.modal"
content="ahs.modal.data.text"></pagedown>
最佳答案
指令不能是 $dirty
,并非没有手动黑客攻击或正确的元素类型。
安 input
, textarea
, form
可以变成$dirty
然后将收到 ng-dirty
类(所以是的,一个指令,其中元素是其中之一 - 完整的指令可以是 $dirty,如果这是一个人想要的推理方式)。
你可以做的是用 form
替换指令元素元素,并且对所述表单内的输入控件的任何操作都会在表单上设置适当的 $dirty flah/dirty 类。
像这样:
.directive('', function () {
return {
replace: true,
template: '<form name="myForm"></form>'
}
});
newElement
的内容包装起来。与
form
而不是
div
,并接受整个指令模板不会被标记为
$dirty
的事实。 .
var newElement = $compile(
'<form name="myForm">' +
'<div class="wmd-panel">' +
'<div data-ng-hide="modal.wmdPreview == true" id="wmd-button-bar-' + editorUniqueId + '"></div>' +
'<div>' +
'<textarea data-ng-hide="modal.wmdPreview == true" class="wmd-input" id="wmd-input-' + editorUniqueId + '" ng-model="content" >' +
'</textarea>' +
'</div>' +
'</div>' +
'</form>')(scope)
;
$dirty
(唉,我不明白为什么) - 你可以做这样的事情(考虑到上述变化):
scope.$watch('myForm.$dirty', function (v) {
attrs.$set('dirty', !!v);
});
$dirty
作为包含指令元素的属性,如
$dirty
不是有效的属性名称。我相信这与您会得到的差不多。
$dirty
标志在您的范围内。如果您查看检查器,将设置类,但只有当您在
$scope
上公开表单对象时,这些标志才可用。 (通过命名来完成)。
<form name="myForm">
<pagedown-directive></pagedown-directive>
<button ng-disabled="!myForm.$dirty"></button>
</form>
myForm.$dirty
时才应该启用按钮是
true
.根据我的经验/我所看到的,隔离范围不会破坏表单内的事物流动,因此您应该在那里被覆盖。
关于angularjs - 如何将 pagedown 指令设置为 $dirty?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31477050/
我正在使用 pagedown现在在我的网站上,到目前为止它很棒,唯一的细节是它不是面向编程的网站,所以我想删除“代码”按钮。 有什么办法可以做到吗?我尝试使用 CSS 隐藏按钮,但 html 具有内联
我正在尝试使用 Pagedown将 markdown(包含代码部分)解析为 html。 它基本上有效,但我注意到一个奇怪的行为。如果我的 Markdown 中有这个: `ArrayList names
这是我的代码: --- title: "A Multi-page HTML Document" author: "Yihui Xie and Romain Lesur" date: "`r Sys.D
我为此尝试了下面的代码,但它仅将向下翻页按钮添加到第一个 .wmd-input。 if ($(".wmd-input").length > 0) { var converter = new M
我正在尝试复制原始 img标签在自定义中的功能 img将添加到 pagedown 转换器的标记。 例如,我复制原始行为: ![image_url][1] [1]: http://lolink.com给
我正在使用 node.js 创建一个博客,但我仍在争论是否要使用 PageDown 还是坚持使用目前拥有的任何内容。 我当前的 Markdown 编辑器允许用户不受任何限制地输入他们想要的任何代码,有
在Emacs中,为什么我按PageUp再按PageDown,光标并没有回到初始位置,而是回到了页面的其他地方。有什么办法让它做到这一点?例如,让 PageUp 和 PageDown 仅将光标向上或向下
我使用 Pagedown这需要将 wmd-input 的 id 提供给 textarea。在Markdown.Editor.js中是这样写的: function PanelCollection(pos
我在使用 getSanitizingConverter() 时遇到问题。当我尝试使用以下代码时: var plainText; var markdown = new Markdown.Converte
我正在尝试使用 pagedown - Markdown Converter 将 markdown 文本转换为 HTML。它的格式不正确。 这是 JsFiddle URL,它似乎适用于某些标签 - ht
有谁知道如何使用 Hook 或从 Pagedown 编辑 Markdown.Editor.js 以创建内联链接而不是引用链接? 例如,我希望在单击链接按钮时发生这种情况: [inline link](
我使用 pagedown 进行 markdown 编辑,并且已经使用 insertImageDialog 覆盖插入图像的默认对话框。现在我想为插入链接做同样的事情。我找到了 plainLinkText
我正在尝试使用 ctrl+pageup 或 ctrl+pagedown 在 pycharm 中打开的文件之间跳转。 我正在尝试在 pycharm 中执行此操作 - 没有骰子。这可能是因为我切换到“ec
大家好,我试图解决这个问题,但我无路可走: 这是我的代码: --- title: "A Multi-page HTML Document" author: "Yihui Xie and Romain
我想登录并导航到另一个大型机页面。 我需要一个接一个地打开三个屏幕。打开第一个屏幕后,应返回主菜单,快捷键为“PageDOWN”。 在 VBA 中使用 SendKeys。 CreateObject("
我有以下 pagedown 指令。每当我更改/编辑文本区域时,如何将指令设置为脏? app.directive('pagedown', ['$compile', '$timeout', functio
我已经设置了一个以 PageDown 作为键手势的自定义命令,但是对于绑定(bind)到该命令的 MenuItem,该手势显示为“下一步”。问题是我有使用 PageUp、Home 和 End 来执行相
我正在学习 Eclipse 插件开发,通过查看现有内置插件本身的实现可以完成大量学习。当我寻找在选项卡之间切换的快捷方式时,我发现了这个 --> Eclipse HotKey: how to swit
See bottom of question for an improved solution to this problem 我已经尝试了一段时间来获得向下翻页工作的指令。这与 stackoverf
我正在使用 jQuery inline editing plugin Jeditable .谢天谢地,Jeditable provides a plugin capability用于扩展它提供的开箱即
我是一名优秀的程序员,十分优秀!