angularjs-directive

AngularJS directive only when the condition is true

只愿长相守 提交于 2019-12-19 04:48:51
问题 I am going to have a contextmenu directive in ng-repeat items. Based on whether a condition is true, the directive should be applied. How do I put a condition like only when item.hasMenu == true then apply the directive ? <ul ng-controller="ListViewCtrl" > <li contextmenu ng-repeat="item in items">{{item.name}} </li> </ul> EDIT This seems to have worked for me. First the directive. app.directive('menu',function(){ return { restrict : 'A', link : function(scope,element,attrs){ if(scope.hasMenu

angularjs validate input and prevent change if invalid

前提是你 提交于 2019-12-19 03:59:35
问题 I neeed an input field where I can enter only the values 1,2 or 3 so i'm trying to build a directive which prevents all changes to the model if it doesn't match these values. eg the value is 1 and I change it to 5 it should be still 1. I've put together a small fiddle http://jsfiddle.net/kannix/Q5YKE/ but it's most likely wrong to use the $parsers. app.directive('myvalidator', function () { return { require: 'ngModel', link: function (scope, elm, attrs, ctrl) { var validValues = [1,2,3]; ctrl

AngularJS directive input width resize by keyup

扶醉桌前 提交于 2019-12-19 03:56:13
问题 I created a directive in order to make a input that has width automatically resized when keyup (like Google Contacts). However it seems not to be ok, because the width of each characters is different. Could you please help me to give a more optimized way? Tks. http://plnkr.co/edit/DSn0JDDShOXvuXXF9PP2?p=preview 回答1: Based on @notme's answer I created the following gist for my own version of an auto-resizing input angular directive: https://gist.github.com/Zmaster/6923413 Here is the code:

Validating Password And Confirm Password Fields Whenever One Or The Other Fields Model Changes (Each Keystroke) With Angular Directive

旧城冷巷雨未停 提交于 2019-12-19 02:58:30
问题 I currently have an Angular Directive that validates a password and confirm password field as matching. It works to a point, it does throw an error when the passwords do not match. However, it doesn't throw the error until you have entered data in both fields. How can I make it so the error for mismatched passwords is thrown as soon as you enter data in one field or the other? Here is the directive (it has to be added to both fields that need to match): .directive('passwordVerify', function()

AngularJS toggle divs visibility through button

别来无恙 提交于 2019-12-18 20:49:02
问题 I have a multiple sets of two divs and a button for each per page. The two divs contains alternating content that the button should handle switching visibility. I can't seem to think of an Angular solution that can be extensible to multiple separate instances in the page (my mind keeps wanting to get it done in JQuery). I have created a JSFiddle example here. You will see two divs p_table class with <span class="trigger">A</span> . The trigger should alternate the two p_table inside their

Using $emit in angular 1.5 component

五迷三道 提交于 2019-12-18 19:00:35
问题 I am using angular 1.5 component and need to call function in parent controller from when $emit in child component. How we can do this? Example: (function (angular) { 'use strict'; controllerName.$inject = []; function controllerName() { var _this = this; function toBeCalledOnEmit() {//some code} var vm = { toBeCalledOnEmit: toBeCalledOnEmit } angular.extend(_this, vm); } angular.module('moduleName', [ ]).component('parentComponenet', { templateUrl: 'templateUrl', controller: 'controllerName'

How to drag&drop elements onto a calendar with angular directives only

末鹿安然 提交于 2019-12-18 17:26:39
问题 I am trying to implement a drag&drop calendar with angular directives. The calendar uses the ui-calendar (https://github.com/angular-ui/ui-calendar), a complete AngularJS directive for the Arshaw FullCalendar. The drag&drop of the element onto the calendar is powered by angular-dragdrop (https://github.com/codef0rmer/angular-dragdrop). Here is my try in the folder demo/ui-calendar/demo , but no event is ever fired when i drop an element onto the calendar... The html is as simple as following:

angular - reusable dialogs

妖精的绣舞 提交于 2019-12-18 16:51:48
问题 I need to build a dialog to be used with any item on a list of items. The dialog is pretty much the same regardless of the item except for the values of the fields which are obviously item dependent. The directive I am building is reading the template from a file, compiles it with $compile and then binds (links) it to the scope of the item. The result of the binding is a DOM tree. To make the dialog visible I need to append this tree to some element in the existing DOM. The nature of my

AngularJS: Communication between directives

爱⌒轻易说出口 提交于 2019-12-18 13:54:34
问题 I'm writing a directive which creates an mp3/audio player. The issue is that you can have many audio players in one page. What I would like to do is when one is playing and you start an other, that the one currently playing pauses. How can I achieve this with angular directives? Thanks in advance! 回答1: You can also do $rootScope.$broadcast events like playerStarted . This event can be subscribed by all directives and they can react to this event by stopping themselves. The one thing that you

Footable along with Angular.js

对着背影说爱祢 提交于 2019-12-18 13:19:56
问题 I m trying to use footable(http://themergency.com/footable-demo/responsive-container.htm) along with angular.js. As the window size is reduced, Column 3, 4, 5 are only shown when plus sign is clicked. Angular.js provides filtering capabilities, so when I put some search string like below: Rows in the table are filtered. Now the problem is when I try to remove this search string as below: all the rows are again show, but the UI is distorted. I tried to get a callback in angular.js using $scope