Created
November 16, 2013 00:52
-
-
Save ritch/7494351 to your computer and use it in GitHub Desktop.
Connecting Angular to MySQL through LoopBack
This file contains 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
// angular service | |
app.factory('Restaurant', function($resource) { | |
return $resource('/api/restaurants/:id', {id: '@id'}); | |
}); |
This file contains 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
var db = app.dataSource('db', { | |
"connector": require('loopback-connector-mysql'), | |
"host": "demo.strongloop.com", | |
"port": 3306, | |
"database": "demo", | |
"username": "demo", | |
"password": "L00pBack" | |
}); |
This file contains 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
<table class="table table-hover table-striped"> | |
<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> | |
<td> | |
<fm-rating ng-model="$parent.restaurant.rating" readonly="true"></fm-rating> | |
</td> | |
<td> | |
<fm-rating ng-model="$parent.restaurant.price" symbol="$" readonly="true" ></fm-rating> | |
</td> | |
</tr> | |
</table> |
This file contains 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
app.controller('RestaurantsController', | |
function RestaurantsController(Restaurant) { | |
$scope.restaurants = Restaurant.query(filterAndSortRestaurants); | |
}); |
This file contains 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
// LoopBack model | |
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, | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment