angular-directive

How to get element's width/height within directives and component?

这一生的挚爱 提交于 2019-12-02 22:44:11
@Component({ selector: '.donation', template: ` <figure id="donation" move> <img src="image/qrcode.png"/> <figcaption> Buy me a cup of coffee. </figcaption> </figure> ` }) export class DonationComponent{} @Directive({ selector: '[move]' }) export class MoveDirective{} Hey,I want to get element's width/height within MoveDirective and DonationComponent,I read the document several times but still can not find a way to this answer.Do somebody know this please help me,thanks a lot! You can use ElementRef as shown below, DEMO : https://plnkr.co/edit/XZwXEh9PZEEVJpe0BlYq?p=preview check browser's

Pass obj from directive to controller in AngularJS

落爺英雄遲暮 提交于 2019-12-02 18:17:17
问题 I'm trying to write a directive that get the parent controller and parent form controller and pass them as a single object to my controller, this is what I have: HTML: <div ng-controller="ParentController as self" ng-form="ParentForm"> <div ng-controller="ChildController1 as self" my-parent="self.parent"> ChildController1 parent:<br/> {{self.parent}} </div> <br/> <div ng-controller="ChildController2 as self" my-parent="self.parent"> ChildController2 parent:<br/> {{self.parent}} </div> </div>

Pass obj from directive to controller in AngularJS

有些话、适合烂在心里 提交于 2019-12-02 08:14:44
I'm trying to write a directive that get the parent controller and parent form controller and pass them as a single object to my controller, this is what I have: HTML: <div ng-controller="ParentController as self" ng-form="ParentForm"> <div ng-controller="ChildController1 as self" my-parent="self.parent"> ChildController1 parent:<br/> {{self.parent}} </div> <br/> <div ng-controller="ChildController2 as self" my-parent="self.parent"> ChildController2 parent:<br/> {{self.parent}} </div> </div> JS: myApp.directive('myParent', function() { var directive = { restrict: 'A', link: link }; return

Angular img loading directive

邮差的信 提交于 2019-12-02 06:20:49
I am trying to make a simple directive. When the image is loading, the img src will be set to an @Input() string field. On load, the image will be set to the original src value (or at least how I am trying to implement it). I was using the answer here: https://stackoverflow.com/a/38837619/843443 but is isn't a directive, and thus would require a number of changes wherever I use images. My first attempt: loading-img.directive.ts: import { Directive, ElementRef, HostListener, Input } from '@angular/core'; @Directive({ selector: '[tohLoadingImg]' }) export class LoadingImgDirective { imgSrc:

Angular - How to access and replace innerHTML from a directive

大城市里の小女人 提交于 2019-12-02 04:38:15
问题 I am trying to create a directive that modifies the element's innerHTML by adding links to those substrings which start with @ symbol. This is what I have tried so far, linkify.directive.ts constructor(private elementRef: ElementRef, private renderer: Renderer2) { let elementText = this.elementRef.nativeElement.innerHTML; // elementText = '@user mentioned you'; console.log(`Element Text: ${elementText}`); this.renderer.setProperty(this.elementRef.nativeElement, 'innerHTML', this.stylize

unit testing typescript directive template karma-jasmine, html is not defined

自作多情 提交于 2019-12-02 04:33:38
问题 Recently i started unit testing on my typescript code using karma-jasmine. After creating and running test case for a service and a simple directive, i created one test case for custom directive which has one controller(which is injecting one service) and is using 4 scope variable for communicating with outside world. It's a simple unit test case to check whether directive is rendering its template or not. While running this unit test case, karma throws some error 09 03 2016 19:59:27.056:INFO

AngularJS error: Template for directive 'XXXXXX' must have exactly one root element

戏子无情 提交于 2019-12-02 04:23:49
问题 This is a follow-up to this question. I am trying to build and HTML <table> with multiple <tr> rows. I want some of these rows to be rendered by my directive myDirectiveA and others to be rendered by my directive 'myDirectiveB'. Below you can see what my files look like. It all works fine if there is only one <tr> row in the file path/to/myDirectiveA.template.html . But as soon as I add another row in there, I get the following error: `angular.js:13920 Error: [$compile:tplrt] Template for

Writing an Angular directive with a TypeScript class

让人想犯罪 __ 提交于 2019-12-02 01:21:40
I may just be attempting to combine too many "new-to-me" concepts at once, but I am trying to write a custom Angular directive using a TypeScript class. At the moment, I'm not trying to do anything terribly useful, just a POC. I have a TypeScript file that looks like this: module App { 'use strict'; export class appStepper { public link:(scope:angular.IScope, element: angular.IAugmentedJQuery, attrs: angular.IAttributes) => void; public template:string = '<div>0</div><button>-</button><button>+</button>'; public scope = {}; public restrict:string = 'EA'; constructor(){ } public static Factory(

Angular - How to access and replace innerHTML from a directive

岁酱吖の 提交于 2019-12-02 00:30:19
I am trying to create a directive that modifies the element's innerHTML by adding links to those substrings which start with @ symbol. This is what I have tried so far, linkify.directive.ts constructor(private elementRef: ElementRef, private renderer: Renderer2) { let elementText = this.elementRef.nativeElement.innerHTML; // elementText = '@user mentioned you'; console.log(`Element Text: ${elementText}`); this.renderer.setProperty(this.elementRef.nativeElement, 'innerHTML', this.stylize(elementText)); } and I'm using it like this <p linkify> Hey @user check this out! </p> While debugging I

unit testing typescript directive template karma-jasmine, html is not defined

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 23:50:41
Recently i started unit testing on my typescript code using karma-jasmine. After creating and running test case for a service and a simple directive, i created one test case for custom directive which has one controller(which is injecting one service) and is using 4 scope variable for communicating with outside world. It's a simple unit test case to check whether directive is rendering its template or not. While running this unit test case, karma throws some error 09 03 2016 19:59:27.056:INFO [framework.browserify]: bundle built 09 03 2016 19:59:27.063:INFO [karma]: Karma v0.13.21 server