Skip to content

Instantly share code, notes, and snippets.

@superchris
Created May 4, 2015 21:49
Show Gist options
  • Select an option

  • Save superchris/90fc637681fa6270c060 to your computer and use it in GitHub Desktop.

Select an option

Save superchris/90fc637681fa6270c060 to your computer and use it in GitHub Desktop.
JS Bin Factory example // source http://jsbin.com/xaheq/5
<!DOCTYPE html>
<html ng-app="fruit">
<head>
<meta name="description" content="Factory 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="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-controller="FruitCtrl as fruitCtrl">
<ul>
<li ng-repeat="fruit in fruitCtrl.fruits">{{fruit.name}}</li>
</ul>
<script id="jsbin-javascript">
fruit = angular.module("fruit", []);
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" }
]
};
});
fruit.controller("FruitCtrl", function(Fruit) {
this.fruits = Fruit.fruits;
});
</script>
<script id="jsbin-source-javascript" type="text/javascript">fruit = angular.module("fruit", []);
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" }
]
};
});
fruit.controller("FruitCtrl", function(Fruit) {
this.fruits = Fruit.fruits;
});
</script></body>
</html>
fruit = angular.module("fruit", []);
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" }
]
};
});
fruit.controller("FruitCtrl", function(Fruit) {
this.fruits = Fruit.fruits;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment