【发布时间】:2016-08-04 11:25:49
【问题描述】:
我想以两种方式绑定到将包含 json 对象作为文本的文本区域,并且我应该能够以两种方式编辑 textarea 中的 json 对象。 working demo is here
<div ng-app="app">
<div ng-controller="GeojsonController">
<textarea ng-model="geojson"></textarea>
<p>Geojson is: {{geojson | json}} </p>
</div>
</div>
angular.module('app', [])
.controller('GeojsonController', ['$scope', function($scope) {
$scope.geojson = {
"type": "FeatureCollection"
};
}]);
文本区内容为[object Object]
【问题讨论】:
-
| json在做什么? -
@user2181397 将对象转换为 json 字符串
-
$scope.geojson已经是一个 json 对象,这就是为什么你在 textarea 中得到[object Object]的原因,你将不得不使用$scope.geojson作为字符串,然后将字符串转换为 json。
标签: javascript angularjs json