angularjs-directive

Recursive custom directives using ngRepeat

家住魔仙堡 提交于 2019-12-04 02:07:24
I'm trying to create a treeview using AngularJS. Here's my code: module.directive('treeview', function () { return { restrict: 'E', templateUrl: "/templates/ui/controls/treeview.htm", replace: true, transclude: true, scope: {}, link: function (scope, element, attrs) { console.log("treeview directive loaded"); }, controller: function ($scope, $rootScope) { $rootScope.depth = 0; $scope.items = [ { text: "face" }, { text: "palm" }, { text: "cake", childitems: [ { text: "1 face" }, { text: "1 palm" }, { text: "1 cake" } ] } ]; } }; }); module.directive('treeviewItem', function () { return {

AngularJS: Event handler thats executed only once

故事扮演 提交于 2019-12-04 01:33:16
问题 Is there a directive or a way to implement in AngularJS what .one() function achieves with jquery? Ie, to attach an event to an element that gets executed only once. 回答1: Wire up an ng-click to the element you want, then in the ng-click function in your controller have a variable that you toggle to a state that would make the ng-click no longer execute something like var firedOnce = false; scope.myClickFunction = function(){ if(firedOnce){ return; } //other code firedOnce = true; } You could

Custom Angular directive including a dash in the name doesn't work

喜你入骨 提交于 2019-12-04 00:57:48
问题 I've written the following Angular directive that will add the "required" attribute to all children: .directive("requireall", function($compile) { return { restrict: 'A', //only want it triggered for attributes compile: function(element, scope) { // Prevent infinite loop on compile element.removeAttr("requireall"); var allChildren = element.find('*'); allChildren.attr('required', 'required'); $compile(element)(scope); } } }); I really want to call it "require-all" but if I rename it then it

ng-repeat on two arrays

坚强是说给别人听的谎言 提交于 2019-12-04 00:39:52
问题 I want to do a ng-repeat on an array which is composed of two arrays, like this : [titles: [], links: []] My arrays (titles and links) have the same length What i want to print in my ng-repeat, finally, is anything like that : {{ array.title }} {{ array.link }} For example, in a C program i have to do that : int i; i = 0; while (titles[i]) { printf("%s - %s", titles[i], links[i]); i++; } 回答1: It's not clear how you have your data — [titles: [], links: []] isn't meaningful. Ideally you would

ng-class will not trigger on custom directive

偶尔善良 提交于 2019-12-04 00:25:04
问题 I am currently developing a slide menu directive for AngularJS. The javascript consists of three types of directives: the directives for each type of sliding menu (for brevity's sake I only included the left sliding menu), one wrapper directive for the rest of the screen, asmWrapper , and one control button directive, asmControl . Currently, all of these directives are using a service, asmService to communicate. When the user clicks an asmControl, that directive's controller calls a method on

how to set dynamically height to element?

做~自己de王妃 提交于 2019-12-04 00:03:35
I am trying to set dynamically height to element in my demo .I will tell you issue I am taking static or constant value of height in my demo .I take 250px constant value #wrapper{ background-image: url(https://dl.dropboxusercontent.com/s/nz1fzunlqzzz7uo/login_bg.png?dl=0); min-height: 250px; background-repeat: no-repeat; } But I need to add this height dynamically .I got height from this $scope.hgt =$window.innerHeight/3; alert($scope.hgt) But I need to set $scope.hgt to min-height to #wrapper div dynamically?.I don't want to take static value of div height .I want to add dynamically . here is

How to bind boolean values in angular directives?

余生长醉 提交于 2019-12-03 23:29:31
I'd like to bind/set some boolean attributes to a directive. But I really don't know how to do this and to achieve the following behaviour. Imagine that I want to set a flag to a structure, let's say that a list is collapsable or not. I have the following HTML code: <list items="list.items" name="My list" collapsable="true"></list> items are two-way binded, name is just an attribute I'd like that collapsable attribute to be available in the list's $scope either by passing a value (true, false or whatever), either a two-way binding <list items="list.items" name="{{list.name}}" collapsable="list

jQuery Swiper script to run after Ng-Repeat elements are loaded

放肆的年华 提交于 2019-12-03 23:27:58
I'm making a web app using AngularJS, jQuery, HTML, CSS and Bootstrap, and I would like to pick some image links from my JSON that is located in an Apache2 server and use them in order to render those images in my main page. I would also like to swipe them like in a carousel. To make that work, I'm trying to use iDangero.us Swiper . When I pick my images with 3 separated divs, I have no problems. I get my images and then I can normally swipe them as I want. I do it like shown below: Main.html: <div ng-init="initGetRequestMain()"> <div class="swiper-slide" ng-click="swipers()" style="{{data

ng-class does not remove a class that was there before angular was bootstrapped

时光总嘲笑我的痴心妄想 提交于 2019-12-03 23:25:00
Still under 72 hours coming up to speed with angular. Having used knockout for a while, I have to say it's interesting. My question right now has to do with ng-class. Say I have the following: <div class="myClass" ng-class="{myClass: false}"> When angular bootstraps, it does not remove the myClass attribute that was rendered there before. I had expected it to, since that's what ko's css binding does. It seems that angular only removes the class if angular was the one who put it there. So, is there a common workaround for this? Other than creating a custom directive? Since you're only using

What is the React equivalent of an Angular directive that only works on attributes?

两盒软妹~` 提交于 2019-12-03 22:24:08
For example you could have a directive in angular like so: angular.module('app') .directive('classy', function() { return { restrict: 'A', link: function($scope, $el) { $el.addClass('stay-classy'); } } } And implement like so: <div classy></div> There doesn't seem to be an equivalent in React that I've seen after reading through most the docs and googling. I was hoping for something like: ... render: function() { return ( <MyComponent classy></MyComponent> ); } Is there something like that possible that I've been missing? Is there a different yet functionally similar equivalent? Or maybe this