Javascript TypeError:在文本字段中键入时,试图分配给只读属性

Javascript TypeError:在文本字段中键入时,试图分配给只读属性,javascript,angularjs,Javascript,Angularjs,我最近将Angular从1.5.x更新为1.6.4,现在,当我转到表单时,每当我尝试在表单/文本框中键入内容时,都会收到以下错误消息: TypeError: Attempted to assign to readonly property. 这是我的控制器: mainApp.controller('newPostController', ['$scope', '$http', function($scope, $http){ $scope.post = ''; $scope.postCrea

我最近将Angular从1.5.x更新为1.6.4,现在,当我转到表单时,每当我尝试在表单/文本框中键入内容时,都会收到以下错误消息:

TypeError: Attempted to assign to readonly property.
这是我的控制器:

mainApp.controller('newPostController', ['$scope', '$http', function($scope, $http){

$scope.post = '';
$scope.postCreated = false;

$scope.makeNewPost = function() {

    $http.post('/api/post', {
        title:          $scope.post.title,
    })
    .then(function(res){
        $scope.postCreated = true;
        //extra code not related to the form itself...
  };
}]);
我的HTML如下所示:

<form ng-submit="makeNewPost()">
<div class="form-group">
    <label for="title" class="control-label">Title</label>
    <input type="text" autocomplete="off" class="form-control" ng-model="post.title" id="title" required="required">
</div>

<input type="submit" value="Submit">
</form>

标题
我查看了这个错误,我看到的一切都与我的设置无关

请帮我解决这个问题。我不知道从这里到哪里去

谢谢

试试这个

您已初始化
$scope.post=''作为字符串。但是那应该是
$scope.post={}对象

var mainApp=angular.module('app',[]);
mainApp.controller('newPostController',['$scope','$http',函数($scope,$http){
$scope.post={};
$scope.postCreated=false;
$scope.makeNewPost=函数(){
log($scope.post.title);
$http.post(“/api/post”{
标题:$scope.post.title,
})
.然后(功能(res){
$scope.postCreated=true;
//与表单本身无关的额外代码。。。
});
}
}]);

标题

$scope.post
是一个字符串,在其上创建属性正常吗?就是这样!谢谢你指出这一点。想给你买一杯虚拟啤酒!哈哈哈。。。很高兴听到:)这帮我在React Native中找到了同样的问题,这让我抓狂!