1

Can I make the code in ng-model work anyhow, as I need to show the first as well as the last name?

What I basically want is to turn this

{{currentInventory.assigned.first_name + ' ' + currentInventory.assigned.last_name}}

into this:

ng-model="currentInventory.assigned.first_name + ' ' + currentInventory.assigned.last_name"
1
  • 1
    this wont work. if you just want to display these values: <p>{{currentInventory.assigned.first_name}} {{currentInventory.assigned.last_name}}</p> ... ng-model wants to bind a variable, assigning ng-model="currentInventory.assigned.first_name + ' ' + currentInventory.assigned.last_name" makes no sense. Commented Apr 11, 2014 at 7:18

2 Answers 2

2

Aren't you confusing ng-model and ng-bind ?

ng-model purpose is to bind a field to a scope variable. ng-bind purpose is to display a value by evaluating an angular expression like yours

You could also do something as follow :

<textarea ng-model="yourmodel" ng-init="yourmodel="currentInventory.assigned.first_name + ' ' + currentInventory.assigned.last_name" ng-bind="yourmodel"></textarea>

That:

  • binds scope.yourmodel to your field
  • init its value with your expression
  • displays it with ng-bind (or ng-value or other..)
Sign up to request clarification or add additional context in comments.

4 Comments

ng-bind is uni-directional: it is a read-only value. ng-model is bi-directional: the value can be updated (on the front-end, usually inside a form)
@Tone Well yeah obvisouly, am I saying the contrary here ?
firstly it's not obvious to an angularjs novice. Secondly, I'm simply adding to your answer in the spirit of learning so have the grace to accept it as such.
@Tone ha ok sorry but your comment was ambiguous... I though I said something wrong, don't stress.
0

in controller :

$scope.text = $scope.currentInventory.assigned.first_name + ' '+ $scope.currentInventory.assigned.last_name;

in HTML

<input type="text" ng-model="text" />

Append the value in conroller and send that value to model.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.