草庐IT

Linux基本指令

全部标签

javascript - 模板中带有 ng-if 的 angularjs 指令

我正在构建一个在其模板中使用ng-if的指令。奇怪的是提供给链接函数的元素并没有扩展ng-if代码,它只是ng-if的注释行。四处游玩,我发现通过将我的链接代码包装在$timeout中似乎可以让它工作,但我想知道这是否不是正确的方法......更重要的是,为什么会这样。我添加了一个plunk来演示:http://plnkr.co/edit/Gl7v8yJLevi664nUKcFY?p=preview 最佳答案 大多数指令实际上在$watch()中执行它们的大部分逻辑。例如ng-if将在它的属性上设置一个监视,然后在更改时渲染/删除d

javascript - Karma/Jasmine 测试自定义指令 Controller

我正在尝试使用Karma+Jasmine测试AngularJS自定义指令。我找到了一种方法来检查网络上的许多引用资料。但解决方案似乎不是正确的方法。让我们先看一个例子,这是test.js:angular.module("app",[]).directive("test",function(){return{restrict:'E',scope:{defined:'='},templateFile:"test.html",controller:function($scope){$scope.isDefined=function(){return$scope.defined;};}};})

javascript - 将 jquery 插件转换为指令 Angular

我正在尝试将jQuery插件转换为指令。这是图书馆:Github.在文档中有一个选项:$(document).ready(function(){$("#datepicker").datepicker();$("#datepickerbtn").click(function(event){event.preventDefault();$("#datepicker").focus();})});我创建的指令:app.directive('dateP',function(){return{restrict:'A',require:'ngModel',link:function(scope,e

javascript - 基本 d3 : why can you select things that don't exist yet?

我一直在学习d3,我对选择有点困惑。考虑以下示例:http://bl.ocks.org/mbostock/1021841具体来说,让我们看一下这一行:varnode=svg.selectAll(".node").data(nodes).enter().append("circle").attr("class","node").attr("cx",function(d){returnd.x;}).attr("cy",function(d){returnd.y;}).attr("r",8).style("fill",function(d,i){returnfill(i&3);}).styl

javascript - Angular 2 中的指令执行顺序

如果我有一个带有点击处理程序和自定义属性指令的简单按钮,如下所示:Save在我的属性指令中,我使用hoSTListener装饰器来监听点击事件:@Directive({selector:`[attributedirective]`})exportclassAuditPusher{@Input('attributedirective')attributedirective:string='Missingmessage!';@HostListener('click',['$event'])pushAudit(){console.log('text:'+this.attributedirec

javascript - 如何在 Angular 2 中为脚本和样式指定基本 href?

我目前正在研究Angular2,我对如何将样式和脚本注入(inject)index.html有疑问通过AngularCLIbuild命令(我指的是在angular-cli.json中定义的脚本和样式)。问题是我在嵌套位置运行应用程序,例如:http://domain.com/my_app同时可以设置,注入(inject)的脚本和样式总是指向src到根域。即/而不是/my_app.当然,这会在尝试查看页面时导致404。我正在服务/dist直接。Nginx配置:server{server_namedomain.com;listen80;location/my_app{alias/srv/w

javascript - 单击时如何从 Controller 获取数据到指令

当我使用ng-clicked时,我试图从Controller将数据发送到指令链接函数,但是我未能将数据发送到指令,该指令在页面加载时调用第一次这是我的html代码click这是我的Controller.controller('myController',function($scope){$scope.clickMe=function(somedata){$scope.myVal=somedata;};});我的指令.directive('myDirective',function(){return{restrict:'E',scope:{myKey:'='},templateUrl:'

javascript - 使用指令将组件动态添加到子元素

尝试使用指令将组件动态放置到子元素。组件(作为模板):@Component({selector:'ps-tooltip',template:`{{content}}`})exportclassTooltipComponent{@Input()content:string;}指令:import{TooltipComponent}from'./tooltip.component';@Directive({selector:'[ps-tooltip]',})exportclassTooltipDirectiveimplementsAfterViewInit{@Input('ps-toolti

javascript - 如何在括号中设置 jslint ES6 指令?

我收到此错误:“需要一个标识符,却看到了‘const’”,我正在使用括号文本编辑器。我找到了这个答案:“您需要指定es6指令。请参阅JSLint帮助”。但我无法弄清楚如何在括号中指定es6指令。这是我的代码:constsingleQuotes='Singlequotes';constdoubleQuotes="Doublequotes";conststringLiterals=`Stringliterlas`;constresult=singleQuotes+doubleQuotes+stringLiterals;document.querySelector('.basic').inn

javascript - Angular Directive(指令) : Allow just numbers

这里是asampleangulardirectivetopreventtypingnon-numerickeys(StackOverflowanswer).我想写类似thisfiddle的东西在多个输入中使用is-number指令。请注意,由于我的输入中有各种不同的指令,因此我不能使用上述答案更新中建议的相同模板。var$scope;varapp=angular.module('myapp',[]);app.controller('Ctrl',function($scope){$scope.myNnumber1=1;$scope.myNnumber2=1;});app.directiv