Last active
March 24, 2016 20:41
-
-
Save justinobney/3d9df40f64a7a40c4908 to your computer and use it in GitHub Desktop.
Revisions
-
justinobney revised this gist
Jul 3, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ app.controller('Ctrl1', function($scope, DataFactory) { // watch the collection for changes $scope.$watch(watchSource, function(current, previous){ this.items = current; }); function watchSource(){ -
justinobney revised this gist
Jul 3, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ app.controller('Ctrl1', function($scope, DataFactory) { this.items = DataFactory.items; // watch the collection for changes $scope.$watch(watchSource, function(current, previous){ this.items = current }); -
justinobney revised this gist
Jul 3, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ svc.getDataStream = function() { return $q.when(fakeData) .then(function(data) { // here we are clearly reseting the data // to the response of the call.. Why doesn't -
justinobney revised this gist
Jul 3, 2014 . 4 changed files with 9 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,4 @@ app.controller('Ctrl1', function($scope, DataFactory) { // bind the controller property to the service collection this.items = DataFactory.items; @@ -14,7 +12,7 @@ app1.controller('Ctrl1', function($scope, DataFactory) { } }); app.factory('DataFactory', function($q, $timeout) { var svc = {}; svc.items = []; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,4 @@ app.controller('Ctrl1', function(DataFactory) { // bind the controller property to the service collection this.items = DataFactory.items; @@ -15,7 +12,7 @@ app1.controller('Ctrl1', function(DataFactory) { }); // sample "service" for getting data app.factory('DataFactory', function($q, $timeout) { var svc = {}; svc.items = []; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ app.controller('Ctrl1', function(DataFactory) { // bind the controller property to the service collection this.items = DataFactory.items; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,19 @@ var app = angular.module('app', []); app.controller('Ctrl1', function(DataFactory) { this.items = DataFactory.items; DataFactory.getDataStream(); }); app.controller('Ctrl2', function($timeout, DataFactory) { // when this eventually fires and gets *remote* data again // our other controller will automatically sync up // without the need for the $watch function $timeout(DataFactory.getDataStream, 2000); }); app.factory('DataFactory', function($q) { var svc = {}; svc.items = []; -
justinobney revised this gist
Jul 3, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ app1.controller('Ctrl2', function($timeout, DataFactory) { $timeout(DataFactory.getDataStream, 2000); }); app1.factory('DataFactory', function($q) { var svc = {}; svc.items = []; -
justinobney revised this gist
Jul 3, 2014 . 3 changed files with 39 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -12,4 +12,26 @@ app1.controller('Ctrl1', function($scope, DataFactory) { function watchSource(){ return DataFactory.items; } }); app1.factory('DataFactory', function($q, $timeout) { var svc = {}; svc.items = []; svc.getDataStream = function() { var fakeData = [ { id: 1, name: 'name 1' }, { id: 2, name: 'name 2' }, { id: 4, name: 'name 4' } ]; // using $q to fake async data grab return $q.when(fakeData) .then(function(data) { svc.items = data; }); }; return svc; }); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -20,22 +20,19 @@ app1.factory('DataFactory', function($q, $timeout) { svc.items = []; svc.getDataStream = function() { var fakeData = [ { id: 1, name: 'name 1' }, { id: 2, name: 'name 2' }, { id: 4, name: 'name 4' } ]; // using $q to fake async data grab return $q.when(fakeData) .then(function(data) { svc.items = data; }); }; return svc; }); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -18,22 +18,20 @@ app1.factory('DataFactory', function($q, $timeout) { svc.items = []; svc.getDataStream = function() { var fakeData = [ { id: 1, name: 'name 1' }, { id: 2, name: 'name 2' }, { id: 4, name: 'name 4' } ]; // using $q to fake async data grab return $q.when(fakeData) .then(function(data) { // this is the magic angular.copy(data, svc.items); }); }; return svc; }); -
justinobney revised this gist
Jul 3, 2014 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,13 @@ app1.controller('Ctrl1', function(DataFactory) { DataFactory.getDataStream(); }); app1.controller('Ctrl2', function($timeout, DataFactory) { // when this eventually fires and gets *remote* data again // our other controller will automatically sync up // without the need for the $watch function $timeout(DataFactory.getDataStream, 2000); }); app1.factory('DataFactory', function($q, $timeout) { var svc = {}; svc.items = []; -
justinobney revised this gist
Jul 3, 2014 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ var app1 = angular.module('app1', []); app1.controller('Ctrl1', function($scope, DataFactory) { // bind the controller property to the service collection this.items = DataFactory.items; // watch the collection for changes $scope.$watch(warchSource, function(current, previous){ this.items = current }); function watchSource(){ return DataFactory.items; } }); -
justinobney revised this gist
Jul 1, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -13,6 +13,7 @@ app1.factory('DataFactory', function($q, $timeout) { svc.getDataStream = function() { return $q.when(fakeHttpResponse()) .then(function(data) { // this is the magic angular.copy(data, svc.items); }); }; -
justinobney revised this gist
Jul 1, 2014 . 1 changed file with 31 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ var app1 = angular.module('app1', []); app1.controller('Ctrl1', function(DataFactory) { this.items = DataFactory.items; DataFactory.getDataStream(); }); app1.factory('DataFactory', function($q, $timeout) { var svc = {}; svc.items = []; svc.getDataStream = function() { return $q.when(fakeHttpResponse()) .then(function(data) { angular.copy(data, svc.items); }); }; return svc; // ignore for demo purposes only. function fakeHttpResponse() { return [ { id: 1, name: 'name 1' }, { id: 2, name: 'name 2' }, { id: 3, name: 'name 3' }, { id: 4, name: 'name 4' } ]; } }); -
justinobney revised this gist
Jul 1, 2014 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ svc.getDataStream = function() { return $q.when(fakeHttpResponse()) .then(function(data) { // here we are clearly reseting the data // to the response of the call.. Why doesn't // it just databind? svc.items = data; }); }; -
justinobney revised this gist
Jul 1, 2014 . 2 changed files with 8 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,6 @@ app1.controller('Ctrl1', function(DataFactory) { // sample "service" for getting data app1.factory('DataFactory', function($q, $timeout) { var svc = {}; svc.items = []; svc.getDataStream = function() { This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ app1.controller('Ctrl1', function(DataFactory) { // bind the controller property to the service collection this.items = DataFactory.items; // but wouldn't it be so much better // to just call it and let it work DataFactory.getDataStream(); }); -
justinobney revised this gist
Jul 1, 2014 . 1 changed file with 2 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -8,9 +8,7 @@ app1.controller('Ctrl1', function(DataFactory) { // invoke the call to get data DataFactory .getDataStream() .then(function() { // update the controller collection property this.items = DataFactory.items; }.bind(this)); @@ -26,7 +24,7 @@ app1.factory('DataFactory', function($q, $timeout) { // using $q to fake async data grab return $q.when(fakeHttpResponse()) .then(function(data) { svc.items = data; }); }; -
justinobney revised this gist
Jul 1, 2014 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,25 @@ // create the application var app1 = angular.module('app1', []); app1.controller('Ctrl1', function(DataFactory) { // bind the controller property to the service collection this.items = DataFactory.items; // invoke the call to get data DataFactory .getDataStream() .then(function(data) { // update the service collection DataFactory.items = data; // update the controller collection property this.items = DataFactory.items; }.bind(this)); }); // sample "service" for getting data app1.factory('DataFactory', function($q, $timeout) { var svc = {}; svc.items = []; svc.getDataStream = function() { -
justinobney revised this gist
Jul 1, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -13,6 +13,7 @@ app1.controller('Ctrl1', function(DataFactory) { app1.factory('DataFactory', function($q, $timeout) { var svc = {}; svc.items = []; svc.getDataStream = function() { // using $q to fake async data grab -
justinobney created this gist
Jul 1, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ var app1 = angular.module('app1', []); app1.controller('Ctrl1', function(DataFactory) { this.items = DataFactory.items; DataFactory .getDataStream() .then(function(data) { DataFactory.items = data; this.items = DataFactory.items; }.bind(this)); }); app1.factory('DataFactory', function($q, $timeout) { var svc = {}; svc.getDataStream = function() { // using $q to fake async data grab return $q.when(fakeHttpResponse()) .then(function(data) { return data; }); }; return svc; // ignore for demo purposes only. function fakeHttpResponse() { return [ { id: 1, name: 'name 1' }, { id: 2, name: 'name 2' }, { id: 3, name: 'name 3' }, { id: 4, name: 'name 4' } ]; } });