0
我想在控制器中傳遞不同的函數之間的變量。下面是我使用這樣做代碼:角度傳遞變量
HTML:
<table class="flat-table">
<tr>
<th>User</th>
<th>Comment</th>
<th>Date</th>
<th>Controls</th>
</tr>
<tr ng-repeat="doc in guest.docs">
<td>{{doc.value.user}}</td>
<td>{{doc.value.comment}}</td>
<td>{{doc.value.date}}</td>
<td>
<img class="controls" src="styles/delete.png" ng-click="guest.delete(doc.id)" title="Delete">
<img class="controls" src="styles/edit.png" ng-click="guest.visible = true; guest.editBox(doc.id)" title="Edit">
</td>
</tr>
</table>
<div id="signCon">
<form name="addForm" ng-submit="guest.add()">
<textarea type="text" ng-model="guest.signature.comment" id="comment" placeholder="Enter a comment?!" required></textarea>
<br/>
<input type="submit" value="Sign!">
</form>
</div>
</div>
<div id="editCon" ng-show="guest.visible === true">
<h1>Edit</h1>
<p>Here you can alter your comment.</p>
<form name="editForm" ng-submit="guest.submitEdit(guest.editBox.signature)">
<textarea type="text" ng-model="guest.submitEdit.comment" required></textarea>
<br/>
<input type="submit" value="Edit!">
</form>
</div>
ANGULAR:
this.editBox = function(id) {
var that = this;
this.id = id;
this.signature = {};
if(self.visible) {
$http({
url: 'http://ip:5984/guestbook/' + this.id,
method: 'GET',
withCredentials: true,
headers: {
'Authorization': auth_hash(UserService.get().username, UserService.get().password)
}
}).success(function(data, status, headers, config) {
that.signature = data;
console.log(that.signature);
}).error(function(data, status, headers, config) {
console.log("error!")
});
};
};
this.submitEdit = function(signature){
var self = this;
this.comment = '';
this.signature = signature;
console.log(this.signature);
};
的想法是編輯圖像用戶點擊出現一個新窗口時並且他們能夠輸入新評論並重新提交。該窗口顯示正確,我能夠正確拉對象。這是當試圖調用submitEdit函數它似乎不通過簽名變量。我是否正確地做這件事?
您可以發佈完整的控制器代碼。 – 2014-12-10 23:10:00