jjzjj

Directive

全部标签

javascript - Angular : ng-controller on directive does not work on transcluded elements within directive

Here是我的脚本:angular.module('MyApp',[]).directive('mySalutation',function(){return{restrict:'E',scope:true,replace:true,transclude:true,template:'Hello',link:function($scope,$element,$attrs){}};}).controller('SalutationController',['$scope',function($scope){$scope.target="StackOverflow";}])和html:{{

javascript - 在 Angular Directive(指令)中将事件绑定(bind)到 $(document)

我有一个实现某种选择框的指令。现在,当Select框打开并单击它外部的某个地方(文档中的其他任何地方),我需要折叠。这个JQuery代码在我的指令中工作,但我想以“Angular方式”来做:$(document).bind('click',function(e){var$clicked=e.target;if(!$clicked.parents().hasClass("myClass")){scope.colapse();}});我尝试将$document服务注入(inject)我的指令,但没有成功。 最佳答案 我相信,最真实的An

javascript - 在选择框选项上使用 ng-hide 或 ng-show

是否可以使用ng-hide指令隐藏选择框选项?http://jsfiddle.net/cr4UB/OneTwoThree{{myDropDown}} 最佳答案 AngularJS1.1.5有一个指令ng-if可以为你工作。检查这个fiddlehttp://jsfiddle.net/cmyworld/bgsVw/ 关于javascript-在选择框选项上使用ng-hide或ng-show,我们在StackOverflow上找到一个类似的问题: https://s

javascript - 带有 ng-repeat、ng-show "Show more"和延迟加载的 Angular 指令

我使用此指令,遍历数组“myArr”,过滤一些条件。这给了我两个问题,我想就此征求意见:a)ng-show部分在那里是因为我有一个条件可以处理这个:Showmore为了显示或隐藏“显示更多”部分。我想不出另一个关于切换这个和/或项目本身的想法。$scope.visible在Controller内部设置为10,一旦我们开始。我无法使用limitTo,因为它无法让我确定是否还有更多要显示的内容,因为它当然会将数组“切碎”到设定的限制。b)在指令内部,模板打印一个标签。只要这些图像未显示在上述结构中,我如何才能阻止它们加载?提前致谢! 最佳答案

javascript - 如何编写通过选择器切换类的 Angular Directive(指令)

我正在尝试编写一个根据选择器条件切换类的指令:Examplecheckbox我需要以某种方式监视元素及其后代上的DOM更改,但我得到了ng:areqerror.我该怎么做?define(function(require){var_=require('lodash');return{restrict:'A',scope:{object:'@classWhen'},link:function(scope,element){scope.$watchCollection(function(){returnelement.find('*').add(element);},function(){_

javascript - 使用 controllerAs 的指令中的 angularjs Controller 无法工作?

我正在尝试将一些数据放入我的指令创建的范围内。这是我的jsFiddle.下面的代码运行良好.directive('directive1',function(){return:{scope:true,controller:function($scope){$scope.name='world';}}}){{name}}但是这些代码不起作用.directive('directive2',function(){return:{scope:true,controller:function(){this.name='world';},controllerAs:'testCtrl'}}){{tes

javascript - 选择自动完成 Angular Directive(指令)

我正在寻找一种方法使我的选择进入自动完成字段。我知道angularJS指令可以为您提供自动完成功能,但这些指令不允许输入名称(用户看到的)和输入值(系统使用的)不同。但是,我需要一个选择框,因为选项名称(用户将看到)和选项值(系统将使用)不同。我知道有这样一个jQuery插件,selectToAutocomplete,它非常简洁并且运行良好,但我更愿意尽可能多地使用AngularJS。jQueryselectToAutocomplete是否有AngularJS替代品? 最佳答案 AngularUI(http://angular-ui

javascript - Angular : Pass $scope variable as directive attribute

我试图将$scope变量值作为属性传递给自定义指令,但它不起作用。这是HTML代码:{{q.question}}指令是,这里是指令代码:app.directive('checkList',function(){return{restrict:'E',template:function(elem,attrs){console.log(attrs.name);return'YesNo'},link:function(scope,elem,attrs){}};})我正在记录属性attrs.name但我得到的值是"{{q.id}}"而不是q.id的实际值 最佳答案

javascript - Angular Directive(指令)内存泄漏?

我正在使用这个简单的html文件重现我发现的内存泄漏:varapp=angular.module('testApp',[]);app.directive('directive1',function(){return{template:'',scope:true};});app.directive('directive2',function(){functionLeakObject(){}functionFoo(){this.bar=function($scope){$scope.nottheredude;};}return{scope:true,link:function($scope

javascript - 在 Angular Directive(指令)中从父级继承的新范围

假设我这样做:sAngular.app.directive('dostuff',['$compile',function($compile){return{restrict:'C',scope:{someVar:'='},link:function(scope,element,attrs){element.click(function(){//dostuffscope.someVar='somethingelse';vardropdownOutput=template();varcompiledOutput=$compile(dropdownOutput)(scope);scope.$