directive

AngularJS directive toggle menu preventing default for other directive

纵饮孤独 提交于 2019-12-04 16:50:37
So I made a directive for a toggle (drop down) menu in AngularJS. I used the directive for multiple items within the page but I have a small problem. When one item is open and I click another one I want the previous one to close. The event.preventDefault and event.stopPropagation stops the event for the previous item and doesn't close it. Any ideas on how to fix this? Is there a way to perhaps only stop the event within the scope? app.directive('toggleMenu', function ($document) { return { restrict: 'CA', link: function (scope, element, attrs) { var opened = false; var button = (attrs

Angular testing using passThrough in unit testing

青春壹個敷衍的年華 提交于 2019-12-04 16:26:01
问题 I'm trying to test a Directive in Angular, but I can't get the corresponding template to work. The directive lists the templateUrl like so templateUrl: 'directives/listview/view.html' Now when I write any unit-test, I get Error: Unexpected request: GET directives/listview/view.html So I have to use the $httpBackend and respond with something sensible like httpBackend.whenGET('directives/listview/view.html').respond("<div>som</div>"); But really I want to simply return the actual file, and

Alias 403 Forbidden with Apache

≡放荡痞女 提交于 2019-12-04 09:57:41
问题 I'm trying to create a folder named week7 and an html page named hello.html in that folder outside the document root and have it viewed through an Alias directive. I created a folder named week7 out of the Document Root. I chose this location for it: /usr/local/www/week7 while my document root is: /usr/local/www/apache22/data in httpd.conf and under tag, I wrote: Alias /week7 /usr/local/www/week7 <Directory /usr/local/www/week7> Require all granted </Directory> After rebooting the server, I

Detect Ctrl + C and Ctrl + V in an input from browsers

耗尽温柔 提交于 2019-12-04 09:02:54
I am using the direct following and I do not detect the copy and paste with the keys inside the input, would someone know how? Thank you! export class OnlyNumberDirective { // Allow decimal numbers. The \, is only allowed once to occur private regex: RegExp = new RegExp(/[0-9]+(\,[0-9]{0,1}){0,1}$/g); // Allow key codes for special events. Reflect : // Backspace, tab, end, home private specialKeys: Array<string> = [ 'Backspace', 'Tab', 'End', 'Home', 'Delete', 'Del', 'Ctrl', 'ArrowLeft', 'ArrowRight', 'Left', 'Right' ]; constructor(private el: ElementRef) { } @HostListener('keydown', [ '$event

AngularJS Masonry for Dynamically changing heights

风格不统一 提交于 2019-12-04 07:41:21
I have divs that expand and contract when clicked on. The Masonry library has worked great for initializing the page. The problem I am experiencing is that with the absolute positioning in place from Masonry and the directive below, when divs expand they overlap with the divs below. I need to have the divs below the expanding div move down to deal with the expansion. My sources are: http://masonry.desandro.com/ and https://github.com/passy/angular-masonry/blob/master/src/angular-masonry.js /*! * angular-masonry <%= pkg.version %> * Pascal Hartig, weluse GmbH, http://weluse.de/ * License: MIT *

angularjs: directive creates two child scope(not isolation scope)? and how to get scope of an element?

拈花ヽ惹草 提交于 2019-12-04 07:37:18
I am writing my angularjs directive with definition like: return { restrict: 'EA', link: link, scope: true, transclude: true, replace: true, controller: controller, template: '<div class="wizard">' + '<div ng-transclude></div>' + '</div>' }; I notice two scopes was created: < Scope (003) --- parent scope of directive < Scope (004) --- controller scope of directive which I think is child scope created by 'scope=true'. all my functions, properites defined in controller show up in this scope < Scope (005) --- transclude scope which is empty from the document I am expecting only one child scope

AngularJS : What is the best way to bind to a global event in a directive

浪尽此生 提交于 2019-12-04 07:21:46
问题 Imagine the situation in AngularJS where you want to create a directive that needs to respond to a global event. In this case, let's say, the window resize event. What is the best approach for this? The way I see it, we have two options: 1. Let every directive bind to the event and do it's magic on the current element 2. Create a global event listener that does a DOM selector to get each element on which the logic should be applied. Option 1 has the advantage that you already have access to

AngularJS overwrites isolated directive scope

耗尽温柔 提交于 2019-12-04 05:19:05
Usage: <my-directive my-var="true"></my-directive> Directive: app.directive('myDirective', [ function () { var definition = { restrict: "E", replace: false, transclude: false, scope: { myVar: '@', }, controller: ['$scope', function($scope) { console.log($scope.myVar); // "true" $scope.myVar = "false"; console.log($scope.myVar); // "false" setTimeout(function() { console.log($scope.myVar); // "true" (!) }, 100); }] }; return definition; } ]); Console output "true" "false" "true" What is exactly happening here? The variable is passed as string ("true"), I'm changing it, then it get's replaced

Angular Directive attrs.$observe

大憨熊 提交于 2019-12-04 02:59:53
问题 I found this Angular Directive online to add a twitter share button. It all seems staright forward but I can't work out what the attrs.$observe is actually doing. I have looked in the docs but can't see $observe referenced anywhere. The directive just seems to add the href which would come from the controller so can anyone explain what the rest of the code is doing? module.directive('shareTwitter', ['$window', function($window) { return { restrict: 'A', link: function($scope, element, attrs)

Getter & setter support with ng-model in AngularJs

こ雲淡風輕ζ 提交于 2019-12-04 01:28:26
I am trying to get getter/setter support for ng-model by implementing a directive that will take care of getting and setting the values to/from the view/model. I am almost there, but I end up in infinite $digest loops. The idea is to set ng-model="$someFieldToStoreInTheScope", and then have the getter/setter directive do the updates between that field and the getter/setter functions. I use $watch to update the model using the setter expression when the ngModelController updates the field in the scope, and another watch to update that field when the getter expression changes. Have a look at: