草庐IT

指令集与架构

全部标签

javascript - 为密码匹配指令编写单元测试

我在这里有一个指令,我正在尝试编写一个单元测试-第一次做这种事情。我不知道该怎么做。这是指令代码和HTML:app.directive('passwordMatch',[function(){return{restrict:'A',scope:true,require:'ngModel',link:function(scope,elem,attrs,control){varchecker=function(){vare1=scope.$eval(attrs.ngModel);vare2=scope.$eval(attrs.passwordMatch);if(e2!=null)retur

javascript - VueJS 自定义指令函数作为参数

我有一个简单的指令:HTML:varapp=newVue({el:"#app",data:{files:[],},methods:{greet:function(arg){alert(arg);},},});JS:Vue.directive('sample',{bind:function(el,binding,vnode){el.addEventListener('...',function(){//...callback.call(arg,...);});},});但是,我不清楚获取函数和求值的适当语法。在指令中执行此操作的正确方法是什么? 最佳答案

javascript - 如何在不同的上下文中使用 es6 构造函数指令

是否可以通过更改“this”上下文(调用、应用或其他)在另一个实例上使用es6构造函数指令?这可以使用es5“类”。这是我的意思的一个小例子:functionES5(){this.foo='foo';}classES6{constructor(){this.bar='bar';}}vara=newES6();ES5.call(a);console.log(a.foo+a.bar);//foobarvarb=newES5();//Reflect.construct(ES6);??ES6.call(b);//TypeError:ClassconstructorES6cannotbeinvo

javascript - 如何创建一个指令,根据条件在目标元素上添加 ng-class 和 ng-disabled?

我有以下代码:app.directive"ngDisableOnVar",($compile)->restrict:"A"terminal:truepriority:1000replace:falsescope:{}compile:compile=(element,attrs)->cattr=attrs["ngDisableOnVar"]element.attr("ng-class","{'disabled':!#{cattr}}")element.attr("ng-disabled","!#{cattr}")element.removeAttr("ng-disable-on-var"

javascript - 如何为选择列表的自定义指令实现 ng-change?

我的指令使用代码我的指令代码.directive('inputSelect',function(){return{templateUrl:'someTemplate.html',restrict:'E',scope:{ngModel:'=',ngChange:'='}};});我的指令模板因此,当所选项目发生变化时,函数someFunction()被无限次调用(尽管更改只完成一次),应该更改什么以确保someFunction()只调用一次(someFunction()是Controller范围内的一个函数,在该Controller中使用指令)[我确实尝试使用&和@作为ngChange的

javascript - 如何在 AngularJS 中测试 Controller 指令

经过多次研究,我一直无法正确测试Angular指令,因为我无法访问其Controller内的函数。指令代码如下:angular.module('app').directive("accordionItem",function(){return{restrict:'E',replace:true,templateUrl:function(elem,attr){return'partials/invoice/'+attr.temp+'.html';},scope:{invoice:'=',temp:'@'},controller:function($scope,listSelectionS

javascript - 如何在 AngularJs 的指令中使用 $location

我正在创建一个指令,其中onclick将用户带到另一个页面。有点像定制的“href”标签。我希望$location会处理重定向功能,但由于我不知道的原因,这是行不通的。如果我在Controller中使用$location它可以工作,但在指令中,它不会。这是代码:angular.module("myAPP").directive('hpHref',['$location',function($location){return{restrict:"A",link:function(scope,el,attr){el.bind('click',function(){//morelogicco

javascript - $render 在 angular 1.2.2 停止工作(文件验证指令)

昨天我已经从angular1.0.8迁移到angular1.2.2,除了一堆其他的东西坏了而且我已经修复了,以下指令的$render函数不再触发。有没有人遇到过这样的行为?0directive('validFile',function(utils,$filter){return{require:'ngModel',link:function(scope,el,attrs,ngModel){if(utils.isMobileAgent())return;varform=el.parents().find('form');ngModel.$render=function(){debugge

javascript - Angular 文件上传指令不更新 Controller 模型

我正在尝试关注这个[tutorial]但无法正常工作。我的AngularController正在为在我的指令中创建的模型记录undefined。这是一个[JSFiddle]它的工作创造了我的教程作者。问题是View可以找到$scope.myFile而Controller却找不到($scope.myFile是undefined)。View显示{{myFile.name}}(例如my-image.jpg)。myFile变量是一个包含所选文件数据的JS对象。这很好用。该指令似乎正在为模型分配所选文件的值(并因此在View中正确显示)。{{myFile.name}}Click这是我从[tuto

javascript - AngularJS 指令 templateUrl 在加载文件 URL 时返回 400

我在MVC5布局页面中有一个基本指令,其中包含一个用于搜索的指令。我的问题是无法加载templateUrl(400错误)。如果我直接在浏览器中输入URL,我可以毫无困难或错误地加载html页面。我找不到加载页面的AJAX调用失败的原因。Chrome调试器这是在Chrome中加载的HTML页面app.js(function(){varapp=angular.module("mainApp");app.directive("basicSearch",function(){return{templateUrl:'app/directives/basic-search.html',contro