草庐IT

恶意指令

全部标签

javascript - 没有将 "exportAs"设置为 "ngForm"的指令

当我尝试测试LoginComponent时出现以下错误PhantomJS2.1.1(Linux0.0.0):Executed3of55(1FAILED)(0secs/0.307secs)PhantomJS2.1.1(Linux0.0.0)LoginComponentshouldcreateFAILEDFailed:Uncaught(inpromise):Error:Templateparseerrors:Thereisnodirectivewith"exportAs"setto"ngForm"("ivclass="col-md-4col-sm-6col-md-offset-4col-s

javascript - 在模板中访问 Angular Directive(指令)(元素)的文本

所以我关注thisEggHead.iotutorial在自定义组件上,我遇到了这个问题。声明指令时,例如:angular.module('myApp',[]).directive('myDir',function(){return{restrict:"E",controller:"myController",link:function(scope,element,attrs){scope.foo=element.text();},templateUrl:"myDirTemplate.html"}});模板是:Thevalueis:{{foo}}和正在使用的指令如下:...Bar...链

javascript - AngularJS 指令不显示模板

这是我的AngularJs指令。它预期会在模板中显示div,但在代码运行时它什么也没显示。这是html这是AngularJS指令varapp=angular.module('SuperHero',[]);app.directive('SuperMan',function(){return{restrict:'E',template:'HellofromtDirective'}});这里是demo 最佳答案 当您声明您的指令时,您使用了名称SuperMan,但这是错误的。您应该使用superMan因为它将被转换为super-man作为

javascript - Angularjs - 我如何访问 Controller 中的指令属性

我是angularjs的新手,我被困在Controller中访问指令属性。指令app.directive('rating',[function(){return{restrict:'E',scope:{maxStars:'=',url:'@'},link:function(scope,iElement,iAttrs){console.log(iAttrs.url);//works}Controllerapp.controller('ratingController',['$scope','$attrs','$http','$routeParams',function($scope,$a

javascript - Angular 2 - 如何在指令上设置动画?

我有一个指令,我可以在元素上放置检查相关元素当前滚动位置的元素。看起来像这样:@Directive({selector:'[my-scroll-animation]'})每当位置满足某个阈值时,我希望该元素使用动画出现在屏幕上。我知道对于Component我可以附加一个animations属性以及host属性中的一些设置来激事件画。我想要这样的东西:import{myScrollAnimation}from'./animations';@Directive({selector:'[my-scroll-animation]'animations:[myScrollAnimation]//

javascript - 指令内部模板中的 ng-click 未提供功能

ng-click未提供警报。单击指令的内部模板时,不会显示警告框。fiddle链接在这里:http://jsfiddle.net/NNDhX/ 最佳答案 您的指令有其自己的隔离范围。所以函数“hi”应该在指令的范围内。如果你想传递Controller的功能,你应该进行绑定(bind),比如scope:{...,hi:'&'}然后.以下是相关文档的链接:UnderstandingTransclusionandScopes.所以只需将它添加到链接函数中就足够了:link:function(scope,element,attrs){sco

javascript - 你如何处理 AngularJS 指令中的异步数据

这是与thisone类似的问题.我仍然在我的指令中看到一些异步数据的问题。基本上我有我想将数据传递到的指令,并且这些数据是异步获取的。我开始使用指令的scope属性来执行此操作,如下所示:scope:{myAsyncData:'='}在链接函数中,我添加了一个$watch,这样我就可以根据范围内的值更新我的模型。像这样:scope.$watch(scope.foo,function(){//logicbasedonmyAsyncData}当我这样做时,我开始收到javascript错误,因为异步数据尚未返回。这就是促使我发布上面链接的问题的原因。因此,我将$watch更改为如下内容:s

javascript - 如何访问指令链接中的 Controller 功能?

如何从指令链接访问指令Controller函数?传递给链接的波纹管Controller是空的,我想在其中加入show()hide()函数。我当前的指令:app.directive('showLoading',function(){return{restrict:'A',//require:'ngModel',scope:{loading:'=showLoading'},controller:function($scope,$element){return{show:function(){alert("show");},hide:function(){alert("hide");}};}

javascript - 如何在 AngularJS 指令中的元素上绑定(bind)滚动事件

如何在AngularJS指令中的元素上绑定(bind)滚动事件?我在$window上绑定(bind)滚动条,但现在我需要将其更改为此类“.body-wrapper”(angular.element(document.queryselector(.body-wrapper))不起作用)。有什么想法吗?angular.element($window).bind("scroll",function(){...}) 最佳答案 没有理由它不应该工作。这个简单的例子表明它确实如此-varapp=angular.module('plunker',

javascript - 自定义指令中的自动增量值

我的自定义指令模板中有一个关于自动递增数字的问题。我需要的功能是在单击按钮时添加动态HTML内容。主.html指令-ant-add-template-button.jsapp.directive('antAddTemplateButton',function($compile){return{restrict:'A',link:function(scope,element,attrs){$(element).on('click',function(){varcompiledeHTML=$compile('')(scope);$('div.'+attrs.parent).append(c