-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
25 lines (19 loc) · 859 Bytes
/
app.js
File metadata and controls
25 lines (19 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/// <reference path="scripts/angular.js" />
/// <reference path="scripts/angular-resource.js" />
var app = angular.module('SampleApp', ['ngResource']);
app.controller('SampleController', function ($scope, $resource) {
var webapi = $resource('http://code2014-angular-sampleapi.azurewebsites.net/api/bookmarks/:id', { id: '@Id' });
$scope.bookmarks = webapi.query();
$scope.newbookmark = { Title: "", URL: "", Rating: 0 };
$scope.addBookmark = function () {
$scope.bookmarks.push($scope.newbookmark);
webapi.save($scope.newbookmark);
$scope.newbookmark = { Title: "", URL: "", Rating: 0 };
};
$scope.removeBookmark = function (index) {
if (!confirm('sure?')) return;
var bookmark = $scope.bookmarks[index];
$scope.bookmarks.splice(index, 1);
bookmark.$remove();
};
});