0

I'm a bit baffled by Angular. I'm trying to alter a form by giving the fields values from $scope.data but although I know I can "see" the data, I can't get it to display.

When I press on an item on a list I use this to get the data:

ng-click="openModal(data)" 

This opens the modal with the form in it and passes the data to the openModal function. I know it's working because there is a pop-up called in the openModal function that says "You are accessing data:" and then the id of the row, or the title or whatever.

Now what I want is to use the data to alter the view, the form. I want this:

 <input type="text" placeholder="Namegoeshere" value="{{$scope.data.nameOfRecord}}">

All I get in the input field is the text [object.Object] though.

I know the full record is being passed because

console.log("The data is: ", data);

gives me the full record I can inspect in the console.

Why can I not get access to the data in the form?!

2 Answers 2

2

Try to use

 <input type="text" placeholder="Namegoeshere" ng-model="data.nameOfRecord">

instead

 <input type="text" placeholder="Namegoeshere" value="{{$scope.data.nameOfRecord}}">
Sign up to request clarification or add additional context in comments.

1 Comment

This is the one. Thanks! I knew it was something simple like this.
1

Remove $scope from the view(HTML) because {{}} brackets already two way bind scope model with view:- Use:-

<input type="text" placeholder="Namegoeshere" value="{{data.nameOfRecord}}">

1 Comment

I tried that. The answer above was the correct one. Thank you for your input though.

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.