仅桌面上的angularjs条件指令
我只想在一个元素上添加一个指令,如果它不是从移动设备上查看的。由于它是一个外部维护的插件,我不想修改指令本身。最简单的方法是什么 创建一个执行检测(或接收)的指令,如果未从mobile查看,则添加该指令,从元素中删除自身,然后编译该元素 HTML:仅桌面上的angularjs条件指令,angularjs,angularjs-directive,Angularjs,Angularjs Directive,我只想在一个元素上添加一个指令,如果它不是从移动设备上查看的。由于它是一个外部维护的插件,我不想修改指令本身。最简单的方法是什么 创建一个执行检测(或接收)的指令,如果未从mobile查看,则添加该指令,从元素中删除自身,然后编译该元素 HTML: 演示:设备检测是问题的一部分,还是你已经有了这个问题?@tasseKATT我已经有了,但是现在你提到了,如果你也包括这个问题,我将不胜感激,因为我的问题很棘手。 <div not-on-mobile="external-directive"&g
演示:设备检测是问题的一部分,还是你已经有了这个问题?@tasseKATT我已经有了,但是现在你提到了,如果你也包括这个问题,我将不胜感激,因为我的问题很棘手。
<div not-on-mobile="external-directive">Hello.</div>
app.directive('notOnMobile', function($compile) {
// Perform detection.
// This code will only run once for the entire application (if directive is present at least once).
// Can be moved into the compile function if detection result needs to be passed as attribute.
var onMobile = false;
return {
compile: function compile(tElement, tAttrs) {
if (!onMobile) tElement.attr(tAttrs.notOnMobile, '');
tElement.removeAttr('not-on-mobile');
return function postLink(scope, element) {
$compile(element)(scope);
};
}
};
});