angular-directive

What is an AngularJS directive?

强颜欢笑 提交于 2019-11-27 08:56:48
问题 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

Remove host component tag from html in angular 4

烈酒焚心 提交于 2019-11-27 08:54:19
I have a table in which I want to display a table row, which is a component. And also I want to pass data to that component: <table> <th> <td>col 1</td> <td>col 2</td> <td>col 3</td> </th> <tr> <my-component [data1]="data1" [data2]="data2"></my-component> </tr> <tr *ngFor="let item of list"> {{item}} </tr> </table> In my-component , the HTML is a few <td></td> with data rendered from data1 and data2 . But after rendering it, because of <my-component></my-component> my CSS is breaking resulting in all my-component HTML (whole table row) displaying in 1st column. Result of above: <table> <th>

Using 'require' in angular component

旧巷老猫 提交于 2019-11-27 06:39:07
问题 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? 回答1: The cited source is outdated. As of 1.5.0, component controllers can be required in

How to instantiate and apply directives programmatically?

元气小坏坏 提交于 2019-11-27 02:15:06
I know that in ng2 we have ComponentFactoryResolver that can resolve factories that we can apply to a ViewContainerRef . But, is there something similar for directives? a way to instantiate them and apply them to the projected content from a component? No, directives can't be added or removed dynamically. They are only applied to HTML statically added to component templates. What you could do is to enable/disable the directive by passing a parameter ( @Input() ) to the directive to notify it to do something or not. 来源: https://stackoverflow.com/questions/39563547/how-to-instantiate-and-apply

AngularJS Upgrade (1.5 to 1.6,1.7) Makes directive scope bindings undefined

心不动则不痛 提交于 2019-11-27 02:06:15
I have the following code: angular .module('myApp') .directive('layout', function () { return { restrict: 'E', template: '<div ng-include="layoutCtrl.pageLayout"></div>', controller: 'LayoutController', controllerAs: 'layoutCtrl', bindToController: true, scope: { pageLayout: '=', pageConfiguration: '=', isPreview: '=' } }; }); angular .module('myApp') .controller('LayoutController', LayoutController); function LayoutController($scope, LayoutDTO, LayoutPreviewDTO) { var self = this; self.layoutDTO = LayoutDTO; self.layoutPreviewDTO = LayoutPreviewDTO; var test = $scope; if(self.isPreview) self

How to read csv file content in AngularJS?

本小妞迷上赌 提交于 2019-11-27 01:05:50
问题 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> 回答1: with a custom directive: app.directive('fileReader', function() { return { scope: {

Directive to get files input with ng-model [duplicate]

☆樱花仙子☆ 提交于 2019-11-26 22:27:19
问题 This question already has answers here : ng-model for `<input type=“file”/>` (with directive DEMO) (12 answers) Closed last year . Guyz i have an issue with my code i don't know why when i tried to get file from <input ng-model="form.userfile" id="itemImage" name="userfile" type="file"> that code will not give me the values. my code: HTML: <div class="panel panel-default"> <div class="panel-body"> <form id="form" accept-charset="utf-8" ng-submit="sendmessage()"> <textarea ng-model="form

How to extend/inherit components?

空扰寡人 提交于 2019-11-26 18:46:24
问题 I would like to create extensions for some components already deployed in Angular 2, without having to rewrite them almost completely, as the base component could undergo changes and wish these changes were also reflected in its derived components. I created this simple example to try to explain better my questions: With the following base component app/base-panel.component.ts : import {Component, Input} from 'angular2/core'; @Component({ selector: 'base-panel', template: '<div class="panel"

Get Value From Select Option in Angular 4

落花浮王杯 提交于 2019-11-26 17:46:02
问题 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=

is there any alternative for ng-disabled in angular2?

♀尐吖头ヾ 提交于 2019-11-26 15:36:19
问题 I am using angular2 for development and was wondering if there is any alternative for ng-disabled in angular2. For ex. below code is in angularJS: <button ng-disabled="!nextLibAvailable" ng-click="showNext('library')" class=" btn btn-info btn-xs" title="Next Lib >> {{libraries.name}}"> <i class="fa fa-chevron-right fa-fw"></i> </button> Just wanted to know How can I achieve this functionality? any inputs? 回答1: To set the disabled property to true or false use <button [disabled]="