我是angularJS学习关于指令的新手(并且挣扎了很多:))。Angular JS指令 - 完整背景
我想了解的stack overflow question在plunker 一块angularJS代码的用户tasseKATT关于角UI的引导。
我希望有人能更详细地解释这段代码片段。
具体
而且什么是
(value || '').toString();
用于。
从指示片段低于
app.directive('compileHtml', ['$sce', '$parse', '$compile',
function($sce, $parse, $compile) {
return {
restrict: 'A',
compile: function ngBindHtmlCompile(tElement, tAttrs) {
var ngBindHtmlGetter = $parse(tAttrs.compileHtml);
var ngBindHtmlWatch = $parse(tAttrs.compileHtml, function getStringValue(value) {
return (value || '').toString();
});
$compile.$$addBindingClass(tElement);
return function ngBindHtmlLink(scope, element, attr) {
$compile.$$addBindingInfo(element, attr.compileHtml);
scope.$watch(ngBindHtmlWatch, function ngBindHtmlWatchAction() {
element.html($sce.trustAsHtml(ngBindHtmlGetter(scope)) || '');
$compile(element.contents())(scope);
});
};
}
};
}
]);
感谢您长时间的回答,您已经充分回答了我的所有问题。感谢你的帮助。 – user2977259
如果可能,请为$ addBindingClass(tElement)和$$ addBindingInfo添加注释。 – user2977259
增加了更多的解释以及可供参考的链接 – Kop4lyf