Tuesday, October 3, 2017

AngularJS json data not showing on textarea

I’m trying to query data from mongodb database and display the data on a form, following is my json response, the data will not show in textarea but if replace textarea with input field the data is showing, the following does not work

<textarea rows="15" class="form-control" ngmodel="pageContent.content"></textarea>

it works if i replace textarea with input field

<input class="form-control" type="text" ng-model="pageContent.content" />

JSON data

{
  "_id": "59f768a4f26ad23a7c6bfa3d",
  "title": "test title",
  "url": "test url",
  "content": "test content",
  "menuIndex": 4,
  "date": "2017-10-30T18:00:04.113Z",
  "__v": 0
}

View File

<h1></h1>
<hr/>
<form role="form" id="add-page" ng-submit="savePage()">
    <div class="form-group">
        <label>Page ID</label>
        <input class="form-control" type="text" readonly ngmodel="pageContent._id" />
    </div>
    <div class="form-group">
        <label>Page Title</label>
        <input class="form-control" type="text" ng-model="pageContent.title" />
    </div>
    <div class="form-group">
        <label>Page URL Alias</label>
        <input class="form-control" type="text" ng-model="pageContent.url" />
    </div>
    <div class="form-group">
        <label>Menu Index</label>
        <input class="form-control" type="number" ng-model="pageContent.menuIndex" />
    </div>
    <div class="form-group">
        <label>Page Content</label>
        <textarea rows="15" class="form-control" ngmodel="pageContent.content"></textarea>
    </div>
    <input type="submit" class="btn btn-success" value="Save">
    </div>
</form>

Pages Model

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var Page = new Schema({
    title: String,
    url: { type: String, index: { unique: true } },
    content: String,
    menuIndex: Number,
    date: Date
});
var Page = mongoose.model('Page', Page);
module.exports = Page;

Can someone please help me on this?

Source: AngularJS



from Angular Questions https://angularquestions.com/2017/10/03/angularjs-json-data-not-showing-on-textarea/
via @lzomedia #developer #freelance #web #lzomedia.com

No comments:

Post a Comment