Trying to clear the input box after Add is clicked, like the guy is doing in this tutorial.
I have recreated the error without using the API, with this short code.
You can also check out the Plunker.
HTML
<input ng-model="contact.name" type="text">
<button ng-click="Add()">Add</button>
<ul ng-repeat="contact in contactList">
<li>{{ contact.name }}</li>
</ul>
JS
$scope.contactList = [
{name: 'cris'}, {name: 'vlad'}
;]
$scope.Add = function() {
$scope.contactList.push($scope.contact)
$scope.contact = ""
}
It seems that i can add 1 item, but on the second i get this Error:
You didn't clean your contact
object the right way. In the Add()
function, change:
$scope.contact = ""
To:
$scope.contact = {};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With