Extends grunt-loopback-angular. auto-generating Angular $resource services for loopback will include model data for use at runtime on angular client
This plugin requires Grunt ~0.4.5
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-loopback-angular-addmodeldata --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-loopback-angular-addmodeldata');
In your project's Gruntfile, add a section named loopback_angular_addModelData
to the data object passed into grunt.initConfig()
.
Service.options shown are defaults so you can leave them off if using the same. Should look like
loopback_angular_addModelData: {
services: {
options: {
modelConfig: 'server/model-config.json',
serviceFile: 'client/app/scripts/lb-services.js',
modelDir: 'common/models/'
}
}
}
Register task as part of loopback command
grunt.registerTask('loopback', [
'loopback_angular',
'loopback_angular_addModelData', <-- Add this line
'docular'
]);
So what do you get for this? Now when you access loopback resources in angular you can get at the model info stored in the model.json file. As in
//Supposing you have exposed a customer model on your loopback api
function(Customer) {
//figure our what properties the customer model has at runtime
modelProps = Customer.model.properties;
}
I built this because I use angular-formly to automatically generate forms for editing models. By getting access to model properties at runtime and can build out the forms simply based on the fields defined in model.json
(Nothing yet)