angularjs-directive

Extending base directive functionality to other directives

匆匆过客 提交于 2019-12-25 14:06:06
问题 I just wanted to check is this functionality is possible in angularjs. Eg: I have base directive with some common functions but in my whole application all the directives need this functions to be implemented so more code duplication occurs, I am expecting same functionality as extends(inheritance) in Java. Is it possible to achieve this functionality in angularjs.? As per my requirement i can't archive this function by moving this code to services or factory because it is like all of by

In a custom directive, what functionality does `controller` have over `link`?

天涯浪子 提交于 2019-12-25 14:00:45
问题 In trying to get a grasp on creating my own AngularJS directives, I have an example that does everything I need, but realize that in borrowing from various examples, I now can create functionality for the directive's view in both the controller as well as the link . It seems that I could get rid of the controller all together and just put everything into link , or is there something that I can do with the controller that I can't do with link? http://jsfiddle.net/edwardtanguay/gxr49h96/6

Template-Url Directive Unit Testing without Karma

谁说我不能喝 提交于 2019-12-25 11:54:40
问题 SOLUTION = Solution Plunker I have tried manually passing the template in testing - is it even good way of doing it ? How to make it passes !!!!!!! How to write unit test for Simple directive with template-Url without Using Karma . I have tried following after seeing examples on stack-overflow but no success. Directive app.directive("crazy", function () { return { restrict: "A", templateUrl:"directivetemplate.html" }; }); Spec describe('Directive: crazy', function () { beforeEach(module(

send array of attributes to directive

隐身守侯 提交于 2019-12-25 09:28:47
问题 I read about ng-attr for directive, but I want to send array of attributes to directive as example: <myElement attributes="attributes"></myElement> And my directive as example: myApp.directive('myElement', function(){ return { restrict: 'E', require: 'ngModel', template: '<div>' + '<!-- I want to add this attributes on the div element>' + '</div>', replace: true, scope: { attributes: '=attributes' }, } }); And the attributes is in controller as the following: $scope.attributes = {"class":

How to validate against multiple fields and display a unique error?

社会主义新天地 提交于 2019-12-25 08:59:08
问题 I want to validate a control against multiple fields. And I want to display an error indicating which field(s) caused validation to fail. Run the following code. Change the first value to a high number (E.G. 5) and validation will pass. Change the first value to a low number (2) and validation will fail. In the case of "2" there should be 2 errors: model3, model4 because those models are higher values than 2. Similarly for all other fields. The validation works fine. I'm having trouble

Angularjs Directive : html passed as String to directive does not render in template

半城伤御伤魂 提交于 2019-12-25 08:38:41
问题 I have created an angularjs directive called image-multiselect which can be used as follows. <image-multiselect items="landTransportTypes" image="illustrationURL" itemname="name" append="<div class='detail'>...some html here...</div>"></image-multiselect> Notice the append attribute which is assigned an html as string. This html string i expect to use for modifying the template attribute in the DDO as follows function(){ var imageMultiselect = function(){ return { scope : { items: "=", image:

Pass information between directive and controller angularjs

坚强是说给别人听的谎言 提交于 2019-12-25 08:17:41
问题 I have the next directive angular .module('01') .directive('tableSortable', tableSortable); /** @ngInject */ function tableSortable() { return { restrict: 'E', transclude: true, templateUrl: 'app/components/tabla/tableSortable.html', scope: { columns: '=', data: '=', sort: '=', onclickRow: '=' } and I have the next html that shows a table <tbody> <tr ng-click="click(object)" ng-repeat="object in data | orderBy:sort.column:sort.descending | orderBy:sort.column:sort.descending | startFrom

What happens to ng-click and controller access when added by a directive's link function

試著忘記壹切 提交于 2019-12-25 07:58:43
问题 I have a simple JSFiddle: <div ng-controller="MainCtrl as mainCtrl"> <div ng-show="mainCtrl.visible" ng-click="mainCtrl.swap()">Can you see me?</div> <div see-me></div> </div> angular.module('AngularTestApp', []) .controller('MainCtrl', [function () { var self = this; self.visible = true; self.swap = function() { self.visible = ! self.visible; }; }]) .directive('seeMe', [function () { return { template: 'or me?', link: function (scope, element, attrs) { attrs.$set('ng-show', 'mainCtrl.visible

angularJS ES6 Directive

China☆狼群 提交于 2019-12-25 07:47:58
问题 I am trying to develop an application in angular es6 . I have a problem with directve. Here is my code export default class RoleDirective { constructor() { this.template=""; this.restrict = 'A'; this.scope = { role :"@rolePermission" }; this.controller = RoleDirectiveController; this.controllerAs = 'ctrl'; this.bindToController = true; } // Directive compile function compile(element,attrs,ctrl) { console.log("df",this) } // Directive link function link(scope,element,attrs,ctrl) { console.log(

Programmatic Angular Templates?

陌路散爱 提交于 2019-12-25 07:14:35
问题 I am working on a project that uses Angular.js, and a custom jQuery-based control that fires an event with the data that the event pertains to; I want to be able to listen to that event in Angular (easy enough) and then show a dialog box with a template that's bound to that data, so that when the values are changed in the dialog, they are automatically reflected in the object that was sent along with the event. I'm not sure how to do this in Angular, how to render a template on demand that's