Last active
August 29, 2015 14:10
-
-
Save davelnewton/7978ebc4897ea32096ee to your computer and use it in GitHub Desktop.
Why AngularJS* Will Succeed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
$('#trigger').on('click', function(e) { | |
e.preventDefault(); | |
$.ajax({ | |
url: '/books/1/simpleDom', | |
success: function (data) { | |
$('#target').html(data); | |
}, | |
fail: function (data) { | |
alert("AJAX failed!"); | |
} | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="#" id="trigger">Fetch Book Data</a> | |
<div id="target"> | |
Replacement Target | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span class="title"> | |
<%= @book.title %> | |
</span> | |
<span class="author"> | |
<%= @book.author %> | |
</span> | |
<span class="isbn"> | |
<%= @book.isbn %> | |
</span> | |
<span class="available"> | |
<%= @book.available %> | |
</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var simpleExample = {}; | |
simpleExample['SimpleController'] = { | |
trigger: function () { | |
$.ajax({ | |
url: '/books/1/simpleDom', | |
success: function (data) { | |
$('#target').html(data); | |
}, | |
fail: function (data) { | |
alert("AJAX failed!"); | |
} | |
}); | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="#" onclick="return simpleExample.SimpleController.trigger()">Fetch Book Data</a> | |
<div id="target"> | |
Replacement Target | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mod = angular.module('simpleExample', []); | |
mod.controller('SimpleController', function($scope, $http) { | |
$scope.trigger = function(event) { | |
console.log(event.target); | |
$http({ method: 'get', url: '/books/1/simpleDom.json' }) | |
.success(function (data) { | |
$scope.book = data; | |
}) | |
.error(function (data) { | |
alert('AJAX failed!'); | |
}); | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-app="simpleExample"> | |
<div ng-controller="SimpleController"> | |
<a ng-click="trigger()">Fetch Book Data</a> | |
<div> | |
<span class="title"> | |
{{ book.title }} | |
</span> | |
<span class="author"> | |
{{ book.author }} | |
</span> | |
<span class="isbn"> | |
{{ book.isbn }} | |
</span> | |
<span class="available"> | |
{{ book.available }} | |
</span> | |
</div> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment