angularjs-directive

AngularJs Custom Directive fails the text box validation

丶灬走出姿态 提交于 2019-12-12 03:38:42
问题 I have written a custom directive to ensure that a text box can take only integer values. But After using the directive, my $error.required flag always stay false irrespective of whether I have a value in the text field or not. It works fine if I use the native input type, <input name="name" ng-model="testvalue.number" required /> but when I use the custom directive, <number-only-input input-value="testvalue.number" input-name="name"/> shippingForm.name.$error.required is always false and it

Invoking function breaks scope

喜夏-厌秋 提交于 2019-12-12 03:37:39
问题 Same issue as here: AngularJS directive binding a function with multiple arguments Following this answer: https://stackoverflow.com/a/26244600/2892106 In as small of a nutshell as I can. This works: <my-directive on-save="ctrl.saveFn"></my-directive> With: angular.module('app') .controller('MyController', function($scope) { var vm = this; vm.saveFn = function(value) { vm.doSomethingWithValue(value); } }); But when I convert to Typescript and use real classes, this breaks. class MyController {

How to access $rootScope variable from directive templateUrl

守給你的承諾、 提交于 2019-12-12 03:36:40
问题 I've managed to get cross-domain HTML templates working by applying a url to the rootScope which I can access from controllers and other HTML files, but the problem arises when it comes to accessing the template from a directive. Here's my directive code: angular.module("bertha") .directive("bthToggleHeader", function() { var controller = [ "$scope", "$rootScope", "_", function ($scope, $rootScope, _) { if ($scope.tglOpen) $scope.tglShowSection = true; $scope.toggleShowSection = function() {

Add Directive Attribute to Directive Element

大城市里の小女人 提交于 2019-12-12 03:33:13
问题 I have a directive element: return { restrict: 'E', replace: true, transclude: true, template: '<ul>' + '<li {{myNewAttrDirective}}>Home</li>' + '<li {{myNewAttrDirective}}>Products</li>' + '<li {{myNewAttrDirective}}>Cart</li>' + '<li {{myNewAttrDirective}}>Contact Us</li>' + '</ul>', scope: { _showMore : '=showMore' }, link: function(scope, element, attrs) { if (scope._showMore === true) { scope.myNewAttrDirective = 'myAnimationDirective' } } }; HTML: <my-directive show-more="true"></my

Generic error handling in Angular

白昼怎懂夜的黑 提交于 2019-12-12 03:31:57
问题 I am using interceptor in my app for generic error handling when service is down I am getting success response with status 200 even i have changed the base url to test my service. What am i doing wrong?? var myServices = angular.module('myServices', ['ngResource']); myServices.config(function ($provide, $httpProvider) { $provide.factory('ErrorInterceptor', function ($q) { return { response: function(){ return response;// always success?? } responseError: function(rejection) { $scope

Display all days(dates) between two dates in angularjs

随声附和 提交于 2019-12-12 03:26:01
问题 I want to use select " From " and " To " dates from datepicker and display all dates in between, in tabular form using angularjs. 回答1: Try this function to calculate no. of days. Hope it helps function daysCalculator(date1, date2) { var d1 = new Date(date1); var d2 = new Date(date2); var days = d1.getTime() - d2.getTime(); days = parseInt((((days / 1000) / 60) / 60) / 24) return days; } 回答2: Try using this. function getDates(fromDate, toDate) { var dateArray = []; var nextDate = fromDate;

Accessing a directive's scope variable from another directive

青春壹個敷衍的年華 提交于 2019-12-12 03:23:21
问题 I've created a directive that binds the pageYOffset to a scope variable on window scroll like this: app.directive('scrollDirective',function(){ return { restrict: 'E', link: function(scope,elem,attrs){ angular.element(window).bind('scroll',function(){ scope.watchScroll = pageYOffset; }) } } }) And I am trying to access watchScroll variable from another directive like this: app.directive('anotherDirective',function(){ return { restrict: 'A', link: function(scope,elem,attrs){ scope.$watch

Call function after HTML is loaded AngularJS

微笑、不失礼 提交于 2019-12-12 03:19:13
问题 Guys I have the following directive : angular.module('blah').directive('someDirective', function () { return { scope: { arrayParam1: '=arrayParam1', arrayParam2: '=arrayParam2' }, restrict: 'E', templateUrl: '/my/path/to/someDirective.tpl.html', link: function (scope, elem, attrs) { //Some logic scope.someEvent = function(){ //some logic } scope.$on('$viewContentLoaded', function () { debugger; scope.someEvent(); }); } }; }); Now in the HTML I have a ng-repeat over one of the arrays(

How to remove undefined error in angular js?

烂漫一生 提交于 2019-12-12 03:17:25
问题 How to remove undefined error in angular js ?Actually i am trying to load data in using resolve and use that data in controller but on controller i am getting undefined why ? resolve: { message: function (testservice) { return testservice.getdata(); }, message2: function (testservice) { return testservice.getTodo(); }, message3: function (testservice) { return testservice.getGithub(); } } use the controller .controller('b', function($scope, $stateParams, $state, $ionicHistory,message) {

How to access scope in a function inside link function in angularjs directive?

邮差的信 提交于 2019-12-12 03:17:02
问题 This might not be an angularJS problem but I am at my wit's end here. The code is shown below: prep.directive('resultgraph', function () { return { restrict: 'A', link: function (scope, element, attrs) { //** scope accessible here ** DomReady.ready(function () { ThreeBox.preload([ '/scripts/lib/snippets.glsl.html', ], function () { //....scope not accessible here How do I access the scope inside the callback function of 'preload', where it says scope is not accessible here ? 回答1: If you need