0
Wie gebe ich Kommentare mit Angular, wenn jemand auf die Schaltfläche klickt. Jedes Mal, wenn ich etwas Text in das Feld input und textarea eingeben, wird der Text weg sein. Es wird ein leerer Block ohne Namen, Land und Kommentare angezeigt. Der eingegebene Text muss nach dem vorhandenen json gedrückt werden.Wie eingegebene Text in Feldeingabe und Textfeld zu JSON angular
angular.module("forum-page", ["myApp"])
\t .controller("Forum", function($scope) {
\t \t $scope.comments = [
\t \t \t {
\t \t \t "name": "Kevin",
\t \t \t "comment": "Wat een mooi toestel vandaag ontvangen, zeer blij met mijn bestelling :)",
\t \t \t "country": "Nederland"
\t \t \t },
\t \t ];
\t $scope.addComment = function() {
\t \t $scope.comments.push({"name": $scope.name, "comment": $scope.comment, "country": $scope.country});
\t \t $scope.dataObject = {
\t \t \t name: $scope.name,
\t \t \t comment: $scope.comment,
\t \t \t country: $scope.country
\t \t };
\t \t
\t \t $scope.name = "";
\t \t $scope.comment = "";
\t \t $scope.country = "";
\t };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<tr>
<tr><input type="text" id="comment-name" class="comment-form" ng-model="dataObject.name"/></tr>
<tr><input type="text" id="comment-country" class="comment-form" ng-model="dataObject.country"/></tr>
<tr><textarea type="text" id="comment-box" class="comment-form" ng-model="dataObject.comment"/></textarea></tr>
<tr><button ng-click="addComment()">Place comment</button></tr>
</tr>
Thank Männer, hätte nie gedacht, diese Antwort so einfach war. Held! –