Last active
December 28, 2015 11:38
-
-
Save ritch/7494502 to your computer and use it in GitHub Desktop.
An end to end example integrating LoopBack, Angular, and MySQL. Run the full app - http://loopback-foodme.herokuapp.com
View the source - http://github.com/ritch/loopback-foodme
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
<!-- | |
An Angular View to render a list of Restaurants | |
--> | |
<table class="table table-hover table-striped" ng-controller="RestaurantsController"> | |
<tr ng-repeat="restaurant in restaurants"> | |
<td> | |
<a href="#/menu/{{restaurant.id}}"> | |
<img class="img-rounded pull-left" ng-src="img/restaurants/{{restaurant.shortName}}.jpg"> | |
<b>{{restaurant.name}}</b> | |
</a> | |
<p>{{restaurant.description}}</p> | |
</td> | |
</tr> | |
</table> |
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
/** | |
* Define an Angular Controller to bind | |
* our list of restaurants to the view. | |
*/ | |
function RestaurantsController($scope, $resource) { | |
$scope.restaurants = $resource('/api/restaurants').query(); | |
} |
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
/** | |
* Define the LoopBack Resturaunt model. | |
* Surfaces MySQL API over REST. | |
*/ | |
var Restaurant = app.model('restaurant', { | |
dataSource: 'db', | |
properties: { | |
id: {type: String, id: true, generated: true}, | |
shortName: String, | |
price: Number, | |
rating: Number, | |
cuisine: String, | |
opens: String, | |
closes: String, | |
} | |
}); |
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
/** | |
* Connect to MySQL (or Oracle, MongoDB, a backend REST / SOAP Service, etc) | |
*/ | |
var db = app.dataSource('db', { | |
"connector": require('loopback-connector-mysql'), | |
"host": "demo.strongloop.com", | |
"port": 3306, | |
"database": "my-db", | |
"username": "my-username", | |
"password": "secret" | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment