angularjs-directive

from Date I just want to subtract 1 day in javascript/angularjs

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 09:20:59
问题 with the help of new Date() how i can achieve this. my code : var temp =new Date("October 13, 2014 22:34:17"); console.log(new Date(temp-1)); requirement: before: Aug 4, 2014 11:59pm (EDT) after: Aug 3, 2014 11:59pm (EDT) 回答1: You need to specify what amount of time you are subtracting. At the moment its 1, but 1 what? Therefore, try getting the days using getDate() and then subtract from that and then set the date with setDate() . E.g. var temp = new Date("October 13, 2014 22:34:17"); temp

How to Assign value with ng-change in angular js

五迷三道 提交于 2019-12-04 09:02:41
问题 I have simple drop-down bind with angular model <select ui-select2="{allowClear:true}" ng-model="product.Id" ng-change="{value = product.Id == 0}" data-placeholder="Select Warranty"> <option></option> <option ng-repeat="product in products" value="{{product.Id}}">{{product.Code}}</option> </select> How i can assign value depending on some condition in ng-change? 回答1: Your selected value is defined as ng-model . On ng-change you can call a method from the controller and provide the "selected"

Validation for email or phone number for same text field in angularjs

帅比萌擦擦* 提交于 2019-12-04 09:01:15
I am working on registration form for my project in AngularJs. Users can register with his/her Email/Phone. I need to validate that particular text-box. I have validations for both, with different text fields, with ng-pattern. But how can I validate for both in one text field? I have updated my code, here:- enter code here http://plnkr.co/edit/mCVxHxl2DIvqOYtVapRN?p=preview Use /^([_a-z0-9]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,5}))|(\d+$)$/ Demo You can use a pipe '|' to OR two regular expressions together: /<email-pattern>|<phone-pattern>/ so your final regex would be: /^([_a

Partially read-only textbox

蓝咒 提交于 2019-12-04 08:49:39
How to make a text-box partially readonly using angularjs/HTML attribue? For example, a textbox having default value say "+91",which is readonly and else part need to enter values. HTML <input id="field" type="text" value="+91" size="50" /> <div id="output"> </div> Javascript var readOnlyLength = $('#field').val().length; $('#output').text(readOnlyLength); $('#field').on('keypress, keydown', function(event) { var $field = $(this); $('#output').text(event.which + '-' + this.selectionStart); if ((event.which != 37 && (event.which != 39)) && ((this.selectionStart < readOnlyLength) || ((this

Calling directive's methods from parent controller in AngularJS

谁都会走 提交于 2019-12-04 08:28:49
问题 I am using AngularJS with the alias controllers pattern. I can't access (or I don't know how to) directive methods from a parent controller. I have a function inside my controller that should call a directive method but this directive method is not available inside the this controller value. This is what I have. What I am doing wrong? JS angular.module('myApp', []). controller('MyCtrl', function(){ this.text = 'Controller text'; this.dirText = 'Directive text'; this.click = function(){ this

angularjs disable button on $http/$q calls

懵懂的女人 提交于 2019-12-04 08:16:24
问题 following the DRY principal, i want to write a button directive which keeps button disabled for the duration of $http class. I want to do this so as to forbid user from clicking the buttons multiple times, but i am not able to think on how to get function promise status inside a directive, given that the function resides on $scope the scenario is very generic, buttons ng-click does call a function which in turn makes $http calls. on user click : button should get disabled and should be

Check existence of attribute in Angular Directive

喜你入骨 提交于 2019-12-04 08:13:31
问题 Is is possible to check whether a given attribute is present in a directive, ideally using isolate scope or in a worst case scenario the attributes object. With a directive that looked something like this <project status></project> , I want to conditionally render a status icon, but only if the status attribute is present. return { restrict: 'AE', scope: { status: '@' }, link: function(scope, element, attrs) { scope.status === 'undefined' } } Ideally, it would be bound straight to the scope,

ui-codemirror placed within custom directives fails without an error

泪湿孤枕 提交于 2019-12-04 07:53:19
I am trying to use ui-codemirror angular directive from code mirror angular library and the use case is that I have to place it within a custom directive . But when I place it within a custom directive I am unable to see the code mirror in the text area. infact the text area becomes non editable . But when I place it outside the custom directive it works as expected . I am attaching the fiddle code for this http://plnkr.co/edit/NVFuumrGq2FJ8d8EC8Xn?p=preview . I have no option to even debug since there is not even an error . Unable to conclude if it is a bug.Please guide me . Latest Update (17

How to manipulate styles of directive in AngularJS?

谁都会走 提交于 2019-12-04 07:48:27
问题 I'm writing a component using AngularJS and AngularJS directives. I'm doing something like this: var MyApp = angular.module('MyApp', []); MyApp.directive('myTag', function() { return { /* Some logic here*/ } }); I want to be able to change style of my component (using CSS), something like this: <my-tag class="MyClass"></my-tag> Besides this I want to be able to manipulate all elements style inside my component (HTML markup inside of my-tag). Do you have any advice or useful examples how to

Callback function inside directive attr defined in different attr

人走茶凉 提交于 2019-12-04 07:45:00
问题 So I have this directive called say, mySave , it's pretty much just this app.directive('mySave', function($http) { return function(scope, element, attrs) { element.bind("click", function() { $http.post('/save', scope.data).success(returnedData) { // callback defined on my utils service here // user defined callback here, from my-save-callback perhaps? } }); } }); the element itself looks like this <button my-save my-save-callback="callbackFunctionInController()">save</button>