Created
May 4, 2015 21:54
-
-
Save superchris/a9c4ed3e4e6f46f6cfc6 to your computer and use it in GitHub Desktop.
JS Bin Fruit routes example // source http://jsbin.com/devato
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 characters
| <!DOCTYPE html> | |
| <html ng-app="fruit"> | |
| <head> | |
| <meta name="description" content="Fruit routes example" /> | |
| <script src="http://code.jquery.com/jquery.min.js"></script> | |
| <link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" rel="stylesheet" type="text/css" /> | |
| <link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap-responsive.css" rel="stylesheet" type="text/css" /> | |
| <script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap.js"></script> | |
| <script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script> | |
| <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> | |
| <script src="http://code.angularjs.org/1.3.15/angular-route.js"></script> | |
| <meta charset=utf-8 /> | |
| <title>JS Bin</title> | |
| </head> | |
| <body ng-controller="FruitCtrl"> | |
| <ul> | |
| <li ng-repeat="fruit in fruits"><a href="#/fruits/{{fruit.name}}">{{fruit.name}}</a></li> | |
| </ul> | |
| <ng-view /> | |
| <script id="jsbin-javascript"> | |
| fruit = angular.module("fruit", ["ngRoute"]); | |
| fruit.config(['$routeProvider', function($routeProvider) { | |
| $routeProvider. | |
| when('/fruits/:fruitName', {templateUrl: 'templates/recipe.html', controller: "ShowFruitCtrl"}); | |
| }]); | |
| fruit.factory("Fruit", function() { | |
| return { | |
| fruits: [ | |
| {name: "Bananas", description: "Yellow and peely"}, | |
| {name: "Canteloupe", description: "Tell if its ripe by smelling them"}, | |
| {name: "Cherries", description: "Dont try to make jam out of sweet ones"}, | |
| {name: "Strawberries", description: "Picking them is murder on your back"}, | |
| {name: "Tomatoes", description: "People used to think they were poisonous" } | |
| ], | |
| getFruit: function(fruitName) { | |
| return _.findWhere(this.fruits, {name: fruitName}); | |
| } | |
| }; | |
| }); | |
| fruit.controller("FruitCtrl", function($scope, Fruit) { | |
| $scope.fruits = Fruit.fruits; | |
| }); | |
| fruit.controller("ShowFruitCtrl", function($scope, Fruit, $routeParams) { | |
| $scope.fruit = Fruit.getFruit($routeParams.fruitName); | |
| }); | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">fruit = angular.module("fruit", ["ngRoute"]); | |
| fruit.config(['$routeProvider', function($routeProvider) { | |
| $routeProvider. | |
| when('/fruits/:fruitName', {templateUrl: 'templates/recipe.html', controller: "ShowFruitCtrl"}); | |
| }]); | |
| fruit.factory("Fruit", function() { | |
| return { | |
| fruits: [ | |
| {name: "Bananas", description: "Yellow and peely"}, | |
| {name: "Canteloupe", description: "Tell if its ripe by smelling them"}, | |
| {name: "Cherries", description: "Dont try to make jam out of sweet ones"}, | |
| {name: "Strawberries", description: "Picking them is murder on your back"}, | |
| {name: "Tomatoes", description: "People used to think they were poisonous" } | |
| ], | |
| getFruit: function(fruitName) { | |
| return _.findWhere(this.fruits, {name: fruitName}); | |
| } | |
| }; | |
| }); | |
| fruit.controller("FruitCtrl", function($scope, Fruit) { | |
| $scope.fruits = Fruit.fruits; | |
| }); | |
| fruit.controller("ShowFruitCtrl", function($scope, Fruit, $routeParams) { | |
| $scope.fruit = Fruit.getFruit($routeParams.fruitName); | |
| }); | |
| </script></body> | |
| <script id="templates/recipe.html" type="text/ng-template"> | |
| <form name="fruitForm"> | |
| <label>Name: <input name="name" ng-model="fruit.name" /></label> | |
| <label>Description: <input name="description" ng-model="fruit.description" /></label> | |
| <div>Form dirty? {{fruitForm.$dirty}}</div> | |
| <div>Name dirty? {{fruitForm.name.$dirty}}</div> | |
| <div>Description dirty? {{fruitForm.description.$dirty}}</div> | |
| </form> | |
| </script> | |
| </html> |
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 characters
| fruit = angular.module("fruit", ["ngRoute"]); | |
| fruit.config(['$routeProvider', function($routeProvider) { | |
| $routeProvider. | |
| when('/fruits/:fruitName', {templateUrl: 'templates/recipe.html', controller: "ShowFruitCtrl"}); | |
| }]); | |
| fruit.factory("Fruit", function() { | |
| return { | |
| fruits: [ | |
| {name: "Bananas", description: "Yellow and peely"}, | |
| {name: "Canteloupe", description: "Tell if its ripe by smelling them"}, | |
| {name: "Cherries", description: "Dont try to make jam out of sweet ones"}, | |
| {name: "Strawberries", description: "Picking them is murder on your back"}, | |
| {name: "Tomatoes", description: "People used to think they were poisonous" } | |
| ], | |
| getFruit: function(fruitName) { | |
| return _.findWhere(this.fruits, {name: fruitName}); | |
| } | |
| }; | |
| }); | |
| fruit.controller("FruitCtrl", function($scope, Fruit) { | |
| $scope.fruits = Fruit.fruits; | |
| }); | |
| fruit.controller("ShowFruitCtrl", function($scope, Fruit, $routeParams) { | |
| $scope.fruit = Fruit.getFruit($routeParams.fruitName); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment