Skip to content

Instantly share code, notes, and snippets.

@ritch
Last active December 28, 2015 11:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ritch/7494502 to your computer and use it in GitHub Desktop.
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
<!--
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>
/**
* Define an Angular Controller to bind
* our list of restaurants to the view.
*/
function RestaurantsController($scope, $resource) {
$scope.restaurants = $resource('/api/restaurants').query();
}
/**
* 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,
}
});
/**
* 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