angular-ngmodel

ng-model and value combination not working for input text box

笑着哭i 提交于 2019-12-04 07:03:14
I'm having two input text box. I need to combine the values entered in two text boxes and display it in the third. I'm able to display it if I use only the value in the third text box. Box 1: <input type="text" ng-model="entity.name"> Box 2: <input type="text" ng-model="entity.code"> Box 3:Box1+Box 2 <input type="text" value="{{entity.name+ ' + ' + entity.code}}"> However if I use a model name in the third box, the logic doesn't seem to be working: <input type="text" value="{{entity.name+ ' + ' + entity.code}}" ng-model="entity.fullCode"> Can anyone suggest a fix ?? This is a good question as

AngularJS ng-model value is lost after custom validation directive is triggered

浪子不回头ぞ 提交于 2019-12-04 06:46:55
I created a custom validation directive and used it in a form. It can be triggered with no problem, but after the validation is triggered, I found that the model value is just lost. Say I have ng-model="project.key" and after validation, project.key doesn't exist in the scope anymore. I think somehow I understood AngularJS wrong and did something wrong. Code speaks. Here is my html page: <div class="container"> ... <div class="form-group" ng-class="{'has-error': form.key.$invalid && form.key.$dirty}"> <label for="key" class="col-sm-2 control-label">Key</label> <div class="col-sm-10"> <input

How to bind the src of an image to ng-model and extract it in Angular?

可紊 提交于 2019-12-04 04:06:26
I want to bind the source of an image to the source of another image. In the end result, the source of the large image should be bound to the src of the clicked smaller (thumbnail) image. Is this possible using ng-model? Here's what I've got <div> <img ng-src="{{selectedImg.src}}"> </div> <div> <ul ng-repeat="thumb in franchises"> <li> <img ng-src="{{thumb.images[0].list}}" ng-model="selectedImg"> </li> </ul> </div> Saulo Lozano You could do it using ng-click: <div> <img ng-src="{{selectedImg.src}}" alt="{{slide.images[0].list}}"> </div> <div> <ul ng-repeat="thumb in franchises"> <li> <img ng

Trigger ng-model.$formatters to run programmatically

荒凉一梦 提交于 2019-12-04 03:42:55
I'd like a custom control that uses ngModel.$formatters to be able to format data as soon as a server dependency loads in. In my case, it needs to load a lookup table to go from one kind of id to another. $modelValue stores one thing $viewValue displays another. Pretty straight-forward stuff. The trick is that if my lookup table isn't loaded, I can't do the formatting into a $viewValue. Once my data loads, I need to do the following: ngModel.$formatters.push(myFormatter) Tell ngModel to start the pipeline from $modelValue -> $formatters -> $viewValue $render() doesn't work, this just moves the

ngModel with a bind function not working in ng2

丶灬走出姿态 提交于 2019-12-04 01:37:38
If I do in a template of a component something like: <input [(ngModel)]="myProperty"></input> then it works, but if I do it with a function in my component it does not: <input [(ngModel)]="getMyProperty()"></input> Here is the plunkr. Tested on RC6. Why? Try this construction <input [ngModel]="getMyProperty()"></input> use only square brackets. 来源: https://stackoverflow.com/questions/39468450/ngmodel-with-a-bind-function-not-working-in-ng2

Angular JS: ng-repeat with dynamic ng-model

会有一股神秘感。 提交于 2019-12-03 14:18:22
I have this working piece of code that is repeated multiple times, hence would be great for a ng-repeat loop. For example, two instances of my code are the following. <div> <input type="text" ng-model="searchParamaters.userName" placeholder="User Name"/> <i class="fa fa-times" ng-click="resetSearchField(filterParamDisplay[0].param)" ng-show="showParam(filterParamDisplay[0].param)"></i> </div> <div> <input type="text" ng-model="searchParamaters.userEmail" placeholder="User Email"/> <i class="fa fa-times" ng-click="resetSearchField(filterParamDisplay[1].param)" ng-show="showParam

Multiple ng-models on one input field?

徘徊边缘 提交于 2019-12-03 07:20:53
问题 I have a form, and a list of items. I used ng-model="searchFor" to filter out the list of items appropriately (this part is working fine), but I also want to "submit" the item that's filtered out -- which would require ng-model="adding_item.name" on the input field as well (I think). Can you have multiple ng-models on one input field? Is there another way around this? 回答1: Try using ng-change event to capture model value and assign it to other input element with its own ng-model. <script src=

How to two-way bind my own RxJS Subject to an [(ngModel)]?

陌路散爱 提交于 2019-12-03 06:34:55
问题 Is there a short and simple way to pass an RxJS Subject or BehaviorSubject to an an Angular 2 directive for two-way binding? The long way to do it would be as follows: @Component({ template: ` <input type="text" [ngModel]="subject | async" (ngModelChange)="subject.next($event)" /> ` }) I'd like to be able to do something like this: @Component({ template: ` <input type="text" [(ngModel)]="subject" /> ` }) I believe the async pipe is only one-way, so that's not enough. Does Angular 2 provide a

setViewValue in directive on input not updating actual visible input value

半城伤御伤魂 提交于 2019-12-03 01:14:41
I've been fighting with this for almost two days. I hope you guys can help me. Summary: I have problems setting the view value of some input fields programatically. I have a form with inputs whose values are saved before the form is removed (multiple elements and multiple forms possible, user might close a form, and reopen later). On reopening the form I want to restore the previous view values (main reason is to get back also the invalid view values which were not saved in the model). This doesn't work. If I call ctrl.$setViewValue(previousValue) I get the model (visibly) updated (if valid),

How to two-way bind my own RxJS Subject to an [(ngModel)]?

99封情书 提交于 2019-12-02 23:36:08
Is there a short and simple way to pass an RxJS Subject or BehaviorSubject to an an Angular 2 directive for two-way binding? The long way to do it would be as follows: @Component({ template: ` <input type="text" [ngModel]="subject | async" (ngModelChange)="subject.next($event)" /> ` }) I'd like to be able to do something like this: @Component({ template: ` <input type="text" [(ngModel)]="subject" /> ` }) I believe the async pipe is only one-way, so that's not enough. Does Angular 2 provide a short and simple way to do this? Angular 2 uses RxJS too, so I expected there to be some inherent