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