angularjs-directive

angular - update directive template on click

旧城冷巷雨未停 提交于 2020-01-24 05:24:19
问题 I am trying to build a page using Angular. I have two templates, say <script type='text/ng-template' id='a.html'> /*some html using {{data}} */ <div><button>A</button></div> </script> and <script type='text/ng-template' id='b.html'> /*some html using {{data}} */ <div><button>B</button></div> </script> I would like to create a directive that changes its template from a to b and vice versa when the button inside the template gets clicked. I tried several options, looking at other answers to

How do I access Object.keys(object).length from a directive template?

拜拜、爱过 提交于 2020-01-23 05:00:10
问题 I'm trying to create a directive that will list all the errors contained in an errors object ( {phone: ["is required"] }, but only if the object is non-empty . (It doesn't make sense to say "The following errors…" when there were none.) I figured out how to check if an object is empty by testing Object.keys(errors).length . The problem is that I can't figure out how to access Object.keys from my directive template. Is this possible? Since Angular expressions are "evaluated" (using $parse ,

AngularJS: passing boolean value to directive

柔情痞子 提交于 2020-01-23 04:55:38
问题 I can not pass boolean value to my directive. Here is my HMTL: <city-zip city="clientCity" zip="clientZip" requiredParam="'true'"></city-zip> And directive: .directive('cityZip', function() { return { restrict: 'E', templateUrl: '../templates/templateCityZip.html', scope: { city: '=', zip: '=' }, controller: function($scope) {} } }); Any help would be much appreciated. 回答1: HTML <city-zip city="clientCity" zip="clientZip" required-param="true"></city-zip> <city-zip city="clientCity" zip=

How much of a performance difference is between template and templateUrl Angularjs

江枫思渺然 提交于 2020-01-22 20:13:25
问题 How much is there a performance difference between template and templateUrl? Currently I am using template in all my directives, but because I am obsessed with performance, I would like to now, which is faster. And if I use templateUrl + $templateCache, is this faster then only using template in directives? 回答1: I was asking myself the #1 question of your post another day. As no one else answered it before, and I do not have enough rep to post a comment, here are my findings after a few tests

AngularJS : Pass $scope variable as directive attribute

爷,独闯天下 提交于 2020-01-22 13:36:41
问题 I'm trying to pass the $scope variable values to a custom directive as attribute, but it's not working. Here is the HTML code: <ul ng-repeat="q in questions"> <li> {{q.question}} <check-list name="{{q.id}}"></check-list> </li> </ul> The directive is <check-list name={{q.id}}></check-list> , and here is the directive code : app.directive('checkList',function(){ return { restrict:'E', template: function(elem,attrs){ console.log(attrs.name); return '</br> <input type="radio" /> Yes </br> <input

AngularJS Unable to display upload file logs [duplicate]

我只是一个虾纸丫 提交于 2020-01-22 04:02:26
问题 This question already has answers here : ng-model for `<input type=“file”/>` (with directive DEMO) (12 answers) Closed 24 days ago . I am trying to create a file upload function using angularjs which will just accept the file and send it to the server side (Django). To ensure the file upload function is working fine, I've placed multiple console.log in multiple locations. However, none of the logs are displayed. This are my codes: .html: <body ng-app="myApp" ng-controller="appCtrl"> <input

How to export my json data into pdf,excel using angular 2

不羁岁月 提交于 2020-01-21 04:51:25
问题 I have created my Data table from the angular 2 website. Now I want to export my json data to PDF,excel using angular 2 framework. Kindly give me suggestion how can I achieve that or any link if you have. Regards 回答1: Use jsPDF to convert from JSON to PDF. And AlaSQL to convert from JSON to Excel (*.xls, *.xlsx). 回答2: (function () { 'use strict'; angular.module('ngJsonExportExcel', []) .directive('ngJsonExportExcel', function () { return { restrict: 'AE', scope: { data : '=', filename: '=?',

Angular UI Bootstrap date-picker Combined With UI.Mask

[亡魂溺海] 提交于 2020-01-20 21:43:05
问题 I am using the angular UI bootstrap popup date-picker to build a directive that will easily allow me to add the date-picker where need. When I combine this with the uiMask Directive, the values in the input get scrambled when I pick a date. Here is my html : <p class="input-group"> <input type="text" class="form-control" ui-mask="99/99/9999" ng-model="ngModel" ng-model="order.date" datepicker-popup="MM/dd/yyyy" is-open="opened" datepicker-options="dateOptions" date-disabled="disabled(date,

AngularJS : minification issue in directive

让人想犯罪 __ 提交于 2020-01-20 17:09:13
问题 I have yet another issue with minification. This time it's because of the $scope service passed to the directive's controller. See below code: angular.module('person.directives'). directive("person", ['$dialog', function($dialog) { return { restrict: "E", templateUrl: "person/views/person.html", replace: true, scope: { myPerson: '=' }, controller: function ($scope) { $scope.test = 3; } } }]); If I comment out the controller part, then it works fine. As you can see, I've used the array

How to write directive on class in Angular Js?

£可爱£侵袭症+ 提交于 2020-01-19 06:13:24
问题 The restrict option is typically set to: 'A' - only matches attribute name 'E' - only matches element name 'C' - only matches class name 'M' - only matches comment 'C' - only matches class name is not working Class="form-control **valid-vehicleyear** ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required ng-touched" I created a directive on class associated with element. On change of value i want to call a api and change value of other element. But no change is observed on change.