Answer the question
In order to leave comments, you need to log in
I'm learning Angular, I follow the link to the page and the Angular markup is visible, if I then press F5 everything is fine.?
Angular Code
var BookShop = angular.module('BookShop', ['ngResource']);
BookShop.factory("BookFactory", function($resource) {
return $resource("books/:id", { id: '@id' }, {
index: { method: 'GET', responseType: 'json' },
update: { method: 'PUT', responseType: 'json' }
});
})
BookShop.controller("BookCtrl", function($scope, BookFactory) {
$scope.books = BookFactory.index()
$scope.addBook = function() {
book = BookFactory.save($scope.newBook)
$scope.books.push(book)
$scope.newBook = {}
}
$scope.deleteBook = function(index) {
book = $scope.books[index]
BookFactory.delete(book)
$scope.books.splice(index, 1);
}
})
.container
h1 Библиотека
div ng-controller="BookCtrl"
.well
h3 Добавить новую книгу
form ng-submit="addBook()"
.row
.col-xs-6
input.form-control ng-model="newBook.name" placeholder=("Название книги") type="text" /
.col-xs-6
input.form-control ng-model="newBook.description" placeholder="Описание" type="text" /
.row
.col-xs-12
br/
input.form-control ng-model="newBook.cover_image" type="text" /
.row
.col-xs-12
br/
input.form-control ng-model="newBook.create_at" type="text" /
.row
.col-xs-12.text-center
br/
input.btn.btn-primary type="Submit" value=("Добавить книгу") /
h3 Доступные книги
hr/
table.table.table-bordered.table-striped
thead
tr
th Имя
th Краткое описание
th Дата создания
th Действия
tbody
tr ng-show="!books.length"
td colspan="4" В библиотеке нет книг
tr ng-repeat=("book in books | orderBy:'-create_at'")
td
| {{ book.name }}
td
| {{ book.description }}
td
|{{ book.create_at }}
td
a.btn.btn-danger ng-click="deleteBook($index)" Удалить
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question