directive

Replace draggable function in angular 2

旧街凉风 提交于 2019-12-25 07:05:35
问题 I am trying to convert an angular directive written in angular 1.* to angular 2. Here is the original directive code: this.directiveModule.directive('draggable', function(CONFIG) { return { restrict: 'A', link: function(scope, elem, attrs) { var setInitPosition; setInitPosition = function() { return elem.css({ top: scope.position.top + 'px', left: scope.position.left + 'px' }); }; elem.draggable({ containment: "parent", stop: function(ev, ui) { return scope.position = { top: ui.position.top,

Unit testing directive with AngularJS + Jasmine

大兔子大兔子 提交于 2019-12-25 03:53:08
问题 I am a new to unit-testing with jasmine, so iI hope this makes sense and is correct enough to get an answer , I am trying to test an angularJS directive here is my plunker : http://jsfiddle.net/ksqhmkqm/13 in my case i am unable to get the input (id="Montid") value in jasmine here is my angualr code app.directive("monthNext", function () { console.log('massif'); return { restrict: 'A', link: function (scope, element) { element.on('input', function () { var todaysYear = new Date(); var u =

Unit testing directive with AngularJS + Jasmine

流过昼夜 提交于 2019-12-25 03:53:02
问题 I am a new to unit-testing with jasmine, so iI hope this makes sense and is correct enough to get an answer , I am trying to test an angularJS directive here is my plunker : http://jsfiddle.net/ksqhmkqm/13 in my case i am unable to get the input (id="Montid") value in jasmine here is my angualr code app.directive("monthNext", function () { console.log('massif'); return { restrict: 'A', link: function (scope, element) { element.on('input', function () { var todaysYear = new Date(); var u =

How to get the current classes of an element in an Angular directive

核能气质少年 提交于 2019-12-25 01:42:55
问题 I have to make an Angular 7 directive where I can toggle (add/remove) a class from the element (ElementRef). When the class in not in the element add it, and when it's in the element remove it. I know how to add / remove a class ... but how to get the current classes of an element ? ... so I can check if I have to add or remove 回答1: To get the current classes of an element, you could do: const elementRef: ElementRef; const classes = elementRef.nativeElement.classList; if (classes.contains(

databinding custom directive angular with replacing html in compile function

做~自己de王妃 提交于 2019-12-25 01:01:48
问题 i am trying to write a directive that replaces an input field with an custom made input field. However, I can not get the databinding to work as the model does not show in the directive input field. I have created a jsFiddle here: http://jsfiddle.net/6HcGS/392/ I guess i dont really know what to place here for the databinding to work: tElement.replaceWith('<input ng-model="ngModel" type="text" />'); If anybody could help me out i would be very grateful as this has been a problem for me for a

AngularJS: Dynamic inputs with form validation

谁说我不能喝 提交于 2019-12-24 15:49:31
问题 I'm creating inputs inside a form dynamically. I created this directive for the purpose: // Generate inputs on the fly using BE data. .directive('inputGenerator', ['$compile', function ($compile) { return { restrict: 'E', scope: { id: '@', type: '@', name: '@', attributes: '=', ngModel: '=', ngDisabled: '=' }, link: function (scope, iElement, iAttrs) { // Get attributes var id = iAttrs.id, type = iAttrs.type, name = iAttrs.name; scope.ngModel[name] = {}; var extended_attributes = { "type":

How can I use special characters in angular directives attributes?

别来无恙 提交于 2019-12-24 05:25:13
问题 I would like to use strings including german characters (Ä, Ö, Ü) in attributes of a custom angularJS directive. For example: <my-custom-directive my-label="Lärm" /> Another example is the ui.bootstrap.tabs directive: <tabset> <tab heading="Lärm"> content ... </tab> <tab heading="Second Heading"> content ... </tab> </tabset> This results in a tab with heading "L�rm". Any ideas? 回答1: Usually in a good editor you can change the document encoding type, the document is saved in. try to set it to

How to use a c-type array as an ivar?

只谈情不闲聊 提交于 2019-12-23 20:27:08
问题 I need a good old-fashioned 2-dimensional array of integers in my program, but no matter how I try to declare it as an ivar, and then use @property/@synthesize, I get one compiler complaint or another. I declare int spotLocations[10] [10] as an ivar. That much works, but then the @property/@synthesize process never passes muster. 回答1: You can't do this. Array variabless can never be lvalues in C, which means you can never declare a function that returns an array, because it would be

angular Accessing ngModel controller in directive with custom template in compile

放肆的年华 提交于 2019-12-23 20:14:49
问题 I want to access the ngModel controller (to later use setValidity to validate the custom input field). However, when I want to use the directive as an attribute (not class), the replaceWith function throws an error that It can not find ngModel controller. I created a fiddle here: jsfiddle.net/6HcGS/396 Can anybody help me out? This is related to my first questions: databinding custom directive angular with replacing html in compile function 回答1: <input zippy ng-model="title"> zippy and

AngularJS之指令

非 Y 不嫁゛ 提交于 2019-12-23 15:52:28
紧接上篇博客“ 初探AngularJS ” 一、前言 在AngularJS中指令尤为重要且内容庞多,固单独提炼出来,梳理一番。如有错误,请不吝讲解。 好了,言归正传,让我们一起走进Angular指令的世界。 在上篇博客的前言部分提到,Angular的核心就是对HTML标签的增强。我们用到的诸如ng-app、ng-controller等等这些都是属于Angular指令,具体点,它们为Angular内置的指令。 Angular不仅提供了内置指令,它还允许我们自定义指令,不然Angular就太low咯。 这也是本篇博客的核心:如何自定义指令。 该篇博客原文地址: http://www.cnblogs.com/giggle/p/5746220.html 二、自定义指令 Angular为我们提供了.directive()这个方法,来定义指令。 如下: 正如上述代码所示,directive方法接受两个参数:name和factory_function。   --name嘛,即为指令的名字,供我们调用时使用;   --factory_function就是当我们调用指令时,指令的实际行为,并且factory_function通常返回一个对象,里面通过规定的设置项来定义指令。 那么自定义指令中,我们都可以操作哪些设置项呢? 如下: var app = angular.module('myApp', [