Skip to content

Instantly share code, notes, and snippets.

Last active December 14, 2015 03:59
Show Gist options
  • Save OdeToCode/5024867 to your computer and use it in GitHub Desktop.
Save OdeToCode/5024867 to your computer and use it in GitHub Desktop.
AngularJS Snippet
<div ng-app="videoApp" ng-controller="VideoController">
<tr data-id="{{video.Id}}" ng-repeat="video in videos">
<button ng-click="editVideo(video)">Edit</button>
<button ng-click="deleteVideo(video)">Delete</button>
<button ng-click="showEdit()">Create Video</button>
<div ng-show="isEditVisible">
<hr />
<input type="hidden" ng-model="editableVideo.Id" />
<input type="text" ng-model="editableVideo.Title" required />
<input type="number" ng-model="editableVideo.Length" min="1" max="360" />
<input type="submit" value="Save" ng-click="saveVideo(editableVideo)" />
@section scripts{
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular-resource.js"></script>
<script src="~/Scripts/underscore.js"></script>
angular.module("videoApp", ["videoService"]);
angular.module("videoService", ["ngResource"]).
factory("Video", function ($resource) {
return $resource(
{Id: "@@Id" },
{ "update": {method:"PUT"} }
var VideoController = function ($scope Video) {
var createVideo = function (newVideo) {
var updateVideo = function(video) {
$scope.showEdit = function () {
$scope.isEditVisible = true;
$scope.editableVideo = new Video();
$scope.saveVideo = function (video) {
$scope.isEditVisible = false;
if (video.Id) {
else {
$scope.editVideo = function (video) {
$scope.isEditVisible = true;
$scope.editableVideo = video;
$scope.deleteVideo = function (video) {
$scope.videos = _.without($scope.videos, video);
$scope.isEditVisible = false;
$scope.videos = Video.query();
Copy link

Very nice example, thanks. Isn't line 57 missing a comma though?

Copy link

Good catch, it is missing a comma.

Copy link

… and line 57 is missing a comma, I think. It should be

var VideoController = function ($scope, Video) {         

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment