angular-ngmodel

Binding private property in [(ngModel)]

陌路散爱 提交于 2020-06-27 16:57:10
问题 How to bind private property in Angular 4? export class newItem{ private id: number; private description: string; private insertDate: any; get getId() : number { return this.id; } set setId(name : number) { this.id = name; } get getDescription() : string { return this.description; } set setDescription(description : string) { this.description = description; } get getInsertDate() : string { return this.insertDate; } set setInsertDate(insertDate : string) { this.insertDate = insertDate; } Here

Angular: forRoot/forChild methods usage?

喜夏-厌秋 提交于 2020-06-10 03:30:54
问题 I was surprised that there is no exact answer to question : What are methods forRoot / forChild made for? For example in RouterModule: Router.forRoot(routes) 回答1: RouterModule#forRoot Creates a module with all the router providers and directives. It also optionally sets up an application listener to perform an initial navigation. While RouterModule#forChild Creates a module with all the router directives and a provider registering routes. The first is usually used to create the initial

Angular 4 ngModel between components

一曲冷凌霜 提交于 2020-01-15 10:14:18
问题 I'm trying to filter my products by categoryId value. Products are listing in product-component. I have a categoryFilter pipe that filters Products and returns list of Product. This pipe requires categoryId but this value is in category-component scope. So my product-component cannot access it. What should I do to make it work? product-component.html <ul class="list-group"> <li class="list-group-item" *ngFor="let product of products |productFilter:filterText|categoryFilter:filterCategory">

AngularJS case-insensitive binding to a static select drop-down

夙愿已清 提交于 2020-01-14 10:12:11
问题 I am trying to perform a case-insensitive bind of an ng-model to a static select drop-down using AngularJS. Consider the select element: <select id="animal" ng-model="ctrl.animal"> <option value="">--- Select ---</option> <option value="Cat">Cat</option> <option value="Dog">Dog</option> </select> If I set ctrl.animal="Cat" in my Angular Controller the binding works fine. The issue is that if I set ctrl.animal="CAT" it does not bind because the strings are not equal as a result of the casing

AngularJS case-insensitive binding to a static select drop-down

戏子无情 提交于 2020-01-14 10:11:25
问题 I am trying to perform a case-insensitive bind of an ng-model to a static select drop-down using AngularJS. Consider the select element: <select id="animal" ng-model="ctrl.animal"> <option value="">--- Select ---</option> <option value="Cat">Cat</option> <option value="Dog">Dog</option> </select> If I set ctrl.animal="Cat" in my Angular Controller the binding works fine. The issue is that if I set ctrl.animal="CAT" it does not bind because the strings are not equal as a result of the casing

ngModel without providing model name in angular 2

吃可爱长大的小学妹 提交于 2020-01-13 07:18:30
问题 <input #gb type="text" pInputText class="ui-widget ui-text" ngModel (ngModelChange)="clearFilter($event)"> I didn't assign any model name to ngModel directive in my code, but Angular 2 accepts this, while AngularJS (1.x) doesn't. Which scenario we need to use this kind of ngModel directive without providing model name? 回答1: Angular 2 accepts it because the object could be set later. A proper way of coding this would be to check if the object exists first, and only then show the object if it

ngModel without providing model name in angular 2

我的梦境 提交于 2020-01-13 07:18:13
问题 <input #gb type="text" pInputText class="ui-widget ui-text" ngModel (ngModelChange)="clearFilter($event)"> I didn't assign any model name to ngModel directive in my code, but Angular 2 accepts this, while AngularJS (1.x) doesn't. Which scenario we need to use this kind of ngModel directive without providing model name? 回答1: Angular 2 accepts it because the object could be set later. A proper way of coding this would be to check if the object exists first, and only then show the object if it

Value in ng-model doesn't update

为君一笑 提交于 2020-01-06 20:18:56
问题 I'm using this <textarea class="notes" placeholder="Placeholder Text" style="height: 630px;" ng-model="notes"></textarea> and from what I can understand ng-model="notes" means that the textarea is assigned whatever $scope.notes is. This works correctly, however whenever I edit the text in the textarea, isn't $scope.notes supposed to change as well? When I use this button: <button ng-click="saveNotes(notes)"></button> The value of "notes" is always the original $scope.notes value and not the

Angular ngChange handler gets old value

爷,独闯天下 提交于 2020-01-06 20:18:12
问题 I am creating angular directive, which wraps html input with bootstrap form group. I use ng-change event to listen to changes, but I get old value inside ng-change handler.To show this, I created to identical directives, one uses ng-keyup and another uses ng-change event to listen to changes. var app = angular.module('app', []); app.controller('home', function() { this.textKeyUp = 'KeyUp'; this.textNgChange = 'NgChange'; this.textKeyUpChanged = function() { console.log('Changed on KeyUp:',

Unsure how to apply two-way binding on Angular for a custom component

纵然是瞬间 提交于 2020-01-06 05:50:07
问题 I have a view component that fetches the data model from a service and sets it as a property on itself. Then, a set of custom components recieve the fields of the property as input to display within them. This works as expected. <app-textbox [caption]="'First name'" [value]="data.name.first"></app-textbox> ngOnInit() { this.service.getData() .subscribe(res => this.data = res); } When the custom component gets its contents edited, I noticed that the original model isn't updated. After some