passiert Ich habe die folgende Anweisung:AngularJS: Wie Funktion in der Kompilierung
app.directive('pagedownAdmin', ['$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'
},
template: '<div class="pagedown-bootstrap-editor"></div>',
link: function (scope, iElement, attrs) {
var editorUniqueId;
if (attrs.id == null) {
editorUniqueId = nextId++;
} else {
editorUniqueId = attrs.id;
}
scope.hideDiv = function() {
document.getElementById("wmd-button-bar-" + editorUniqueId).style.display = 'none';
};
scope.showDiv = function() {
document.getElementById("wmd-button-bar-" + editorUniqueId).style.display = 'block';
};
scope;
var newElement = $compile(
'<div>' +
'<div class="wmd-panel">' +
'<div data-ng-hide="modal.wmdPreview == true" id="wmd-button-bar-' + editorUniqueId + '" style="display:none;"></div>' +
'<textarea on-focus="showDiv()" on-blur="hideDiv()" data-ng-hide="modal.wmdPreview == true" class="wmd-input" id="wmd-input-' + editorUniqueId + '" ng-model="content" >' +
'</textarea>' +
'</div>' +
'<div data-ng-show="modal.wmdPreview == true" id="wmd-preview-' + editorUniqueId + '" class="pagedownPreview wmd-panel wmd-preview">test div</div>' +
'</div>')(scope)
;
iElement.append(newElement);
var help = angular.isFunction(scope.help) ? scope.help : function() {
// redirect to the guide by default
$window.open("http://daringfireball.net/projects/markdown/syntax", "_blank");
};
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();
}
}
}]);
Innerhalb ich die showDiv und hideDiv Funktion habe, die Seiteneditor-Menü beim Klicken in dem und aus dem Textbereich würde ein- und ausgeblendet .
ich die Funktionen innerhalb der Kompilierung zu einer Veranstaltung am vorbei:
//First try
<textarea onfocus="showDiv()" onblur="hideDiv()"></textarea>
Wenn ich innen auf und klicken Sie außerhalb des Textarea bekomme ich die Fehler:
Uncaught ReferenceError: on is not defined
Uncaught ReferenceError: off is not defined
//Second try
<textarea on-focus="showDiv()" on-blur="hideDiv()"></textarea>
Wenn ich auf in und aus Textarea passiert nichts. Keine Fehler, aber keine Funktion aufgerufen.
Kann mir jemand in die richtige Richtung zeigen? Danke
Verwenden Sie 'ng-focus' und' ng-blur' anstelle von 'onfocus' und' onblur' bzw. – Samir
Verwenden Sie nicht 'new'als Variablennamen, es ist ein spezieller, den Sie nicht verwenden können als var –
@ Michel der Var-Name 'neu' ist nur für diese Frage Zwecke :) –