angular-directive

Directive doesn't work in a sub module

柔情痞子 提交于 2019-11-29 07:32:17
问题 I can't make the directive work in a lazy loaded module. I've read the documentation and I simply added the directive into declarations array of my main module. The directive works as expected at that module, but it doesn't work in lazy loaded modules. It even prevents lazy loaded module to be opened because of the template error: Can't bind to 'myHighlight' since it isn't a known property of 'p' Here's my Plunker. Check out errors in console after clicking 'go to child' 回答1: That's because

Angular 2 - How does ng-bootstrap provide the NgbRadioGroup and NgbButtonLabel to their NgbRadio directive?

落花浮王杯 提交于 2019-11-29 04:53:31
Here is the label code: import {Directive} from '@angular/core'; @Directive({ selector: '[ngbButtonLabel]', host: {'[class.btn]': 'true', '[class.active]': 'active', '[class.disabled]': 'disabled', '[class.focus]': 'focused'} }) export class NgbButtonLabel { active: boolean; disabled: boolean; focused: boolean; } and here is the radio button code: import {Directive, forwardRef, Input, Renderer2, ElementRef, OnDestroy} from '@angular/core'; import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms'; import {NgbButtonLabel} from './label'; const NGB_RADIO_VALUE_ACCESSOR = { provide:

Get Value From Select Option in Angular 4

一世执手 提交于 2019-11-29 01:13:09
How do I get the value from the select option in Angular 4? I want to assign it to a new variable in the component.ts file. I've tried this but outputs nothing. Can you also do it using [(ngModel)]? component.html <form class="form-inline" (ngSubmit)="HelloCorp(f)" #f="ngForm"> <div class="select"> <select class="form-control col-lg-8" #corporation required> <option *ngFor="let corporation of corporations" [value]="corporationObj">{{corporation.corp_name}}</option> </select> <button type="submit" class="btn btn-primary manage">Submit</button> </div> </form> component.ts HelloCorp() { const

ng-repeat sorting arrow not working in javascript datatables

a 夏天 提交于 2019-11-29 00:10:01
I'm very new to AngularJs and datatables. I have a requirement to populate the data in table rows using ng-repeat. Iam able to populate the rows and enabling the sorting for the first time. When i click on the arrows to sort ascend or descend the row data wiping off. Here is my table data <table datatable="ng" id="example" class="display" cellspacing="0" width="100%"> <thead> <tr> <th class="col1">Campaign Name</th> <th class="col4">Description</th> <th class="col5">Activate/Deactivate</th> <th class="col5">edit</th> <!-- <th class="col5">status</th> --> <!-- <th class="col5">Details</th> -->

Angular 1.5 component vs. old directive - where is a link function?

拈花ヽ惹草 提交于 2019-11-28 16:48:17
I've been reading this nice recent article about new .component() helper in Angular 1.5, which is supposed to help everyone to migrate to Angular 2 eventually. Everything looks nice and simple, but I couldn't find any information about DOM manipulation inside components. There is a template property though, which can be a function and accept $element and $attrs arguments. Still it's not clear to me if that's the replacement for a link function. It doesn't seem so. jody tate EDIT 2/2/16: The 1.5 documentation now covers components: https://docs.angularjs.org/guide/component Some thoughts based

What is an AngularJS directive?

旧时模样 提交于 2019-11-28 14:58:25
I have spent quite a lot of time reading through AngularJS documentation and several tutorials, and I have been quite surprised at how unapproachable the documentation is. I have a simple, answerable question that may also be useful to others looking to pick up AngularJS: What is an AngularJS directive? There should be a simple, precise definition of a directive somewhere, but the AngularJS website offers these surprisingly useless definitions: On the home page : Directives are a unique and powerful feature available in AngularJS. Directives let you invent new HTML syntax, specific to your

Using 'require' in angular component

二次信任 提交于 2019-11-28 11:59:38
According to the docs (specifically, the table comparing directives to components), angular components allow requiring other directives (or is it only components?). However, components do not have a link function, which could give access to the required controller. The source , contrary to documentation, seems to suggest that it is not possible to use 'require' when creating components. Which is true? The cited source is outdated. As of 1.5.0, component controllers can be required in other components (the same applies to directives). An example from the guide shows the way how the components

Angular img loading directive

好久不见. 提交于 2019-11-28 11:00:20
问题 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 '

Attribute property binding for background-image url in Angular 2

落爺英雄遲暮 提交于 2019-11-28 07:20:11
I have been struggling to figure out the best way to dynamically change the background-image attribute in a number of Angular 2 components. In the following example, I am attempting to set the background-image of a div to an @Input value using [ngStyle] directive: import {Component, Input} from '@angular/core'; import { User } from '../models'; // exporting type aliases to enforce better type safety (https://github.com/ngrx/example-app) export type UserInput = User; @Component({ selector: 'profile-sidenav', styles: [ ` .profile-image { background-repeat: no-repeat; background-position: 50%;

How to read csv file content in AngularJS?

耗尽温柔 提交于 2019-11-28 05:52:55
I want to read a csv file and get its content by using AngularJS and HTML5. I want to put the content of the csv file in $scope. I have this code in my html <table align="center" > <tr class="borderless"> <td>Choose .csv file</td> <td><input type="file" name="readCsvFile" id="readCsvFile" accept=".csv"> </td> <td><input type="button" value="Upload" ng-click="uploadCsvFile()"></td> </tr> </table> with a custom directive: app.directive('fileReader', function() { return { scope: { fileReader:"=" }, link: function(scope, element) { $(element).on('change', function(changeEvent) { var files =