采用了棱角分明无法编辑记录 [英] Can't edit record using Angular
问题描述
我要实现编辑功能,任何一本书,但我不能让我的书
。
I want to implement 'edit' feature to any book, but I can't get my book
.
它是如何工作现在:
- 我点击任何记录(即
< TR>
)。 - 我被重定向到
books_edit
状态 - 这个'编辑'页面必须在当前的图书形式的所有数据(但事实并非如此)。
所以,问题是:如何通过本书从图书
状态 books_edit
状态,并提交是否正确?
So, the question is: How can I pass book from the books
state to books_edit
state and submit it correctly?
HTML块:
<tr ng-click="bookCtrl.editBook(book)" ng-repeat="book in bookCtrl.books">
<td>{{ book.name }}</td>
<td>{{ book.author }}</td>
<td>{{ book.price }}</td>
<td>{{ book.pubdate | date }}</td>
<td>{{ book.coverUrl }}</td>
<td>{{ book.pagesCount}}</td>
</tr>
美国:
.state('books_new', {
url: '/books/new',
templateUrl: 'books/book_new.html',
controller: 'BookCtrl as bookCtrl'
})
.state('books_edit', {
url: '/books/edit',
templateUrl: 'books/book_edit.html',
controller: 'BookCtrl as bookCtrl'
})
.state('books', {
url: '/books',
templateUrl: 'books/books.html',
controller: 'BookCtrl as bookCtrl'
})
控制器的方法:
editBook: function(book) {
if (book) {
console.log(book); // logs correct book
$state.go('books_edit'); // tried to send `book` as a parameter, didn't work
}
},
submitBook: function(book) {
if (book) {
console.log(book);
return books.$save(book).then(function(data) {
$state.go('books');
});
}
}
修改片段:
<form class="container col-lg-3" ng-submit="bookCtrl.submitBook(book)">
<div class="input-group">
<label class="col-sm-2 control-label">Назва:</label>
<input type="text" ng-model="book.name" class="form-control">
我试图发送书
在状态的参数,但没有结果。
I've tried to send book
as a parameter in state, but no result.
推荐答案
感谢 @fikkatra 和 @Gurpinder 与此帮助!完整的解决方案如下:
Thanks @fikkatra and @Gurpinder for helping with this! The complete solution is following:
-
这添加到
books_edit
状态:params:一个{数据:空}
在 editBook()
函数的参数发送到下一个状态:
In the editBook()
function send parameters to the next state:
$ state.go('books_edit',{BOOKID:书的$ id,数据:书});
这添加到 bookCtrl
- bookCtrl.currentBook = $ state.params.data;
修改 NG-模型
在视图中 bookCtrl.currentBook.KEY_NAME
这篇关于采用了棱角分明无法编辑记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!