-1
我在裏面或表格的文本區域內有一個ng-model(註釋)。當我打印出範圍時,我一直未定義。這裏是我的代碼ng-model不能在表格中工作
<table>
<thead>
<tr>
<th>Name</th>
<th>Message</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="message in messages">
<td ng-bind="message.message"> </td>
<td ng-bind="message.user"> </td>
<td> <button ng-if= "message.user == name"
ng-click="delete(message._id)">Delete</button></td>
<td><textarea ng-model = "comment"></textarea></td>
<td><button ng-click="enter_comment(message._id, name)">Add Comment</button></td>
</tr>
</tbody>
</table>
這裏是我的控制器
app.controller('welcomeController', ['$scope', '$location', 'welcomeFactory',function($scope, $location, welcomeFactory){
index = function(){
welcomeFactory.get_name(function(returned_data){
$scope.name = returned_data.data.user
})
}
getMessages = function(){
welcomeFactory.get_messages(function(returned_data){
$scope.messages = returned_data.data.message
})
}
index();
getMessages();
$scope.enter_message = function(){
welcomeFactory.new_message($scope.message, $scope.name, function(sendUser){
console.log(sendUser)
index();
getMessages();
})
}
$scope.enter_comment = function(message_id, name){
console.log($scope.comment)
welcomeFactory.new_comment(message_id, name, $scope.comment ,function(sendMessage){
index();
getMessages();
})
}
}]);
有沒有解決辦法? NG-模型的工作時,不是在一個表,但是當在一個表中沒有,
你的控制器是什麼樣的? – Kai
@凱,我剛添加了控制器 – Aaron
請嘗試刪除空格? 'NG-模型= 「評論」'?不知道這是否會有幫助,但看不到其他錯誤 – holtc