restangular icon indicating copy to clipboard operation
restangular copied to clipboard

restangular in ngBoilerplate example

Open lashex opened this issue 13 years ago • 11 comments

I have spent a fair amount of time (too long actually) trying to make a simple template of restangular working in ngBoilerplate. I am sure this is because of my n00b status with both offerings but might you have an example (or even just documentation) showing how to get restangular working in an ngBoilerplate based AngularJS app? I was originally planning on submitting this as a documentation suggestion but that level of contribution is looking pretty remote right now.

Here's all I've done so far:

  • In my ngBoilerplate directory executed bower install restangular --save-dev
  • changed ngBoilerplate package.json to have "name": "boil-rest",
  • Updated index.html with: <html ng-app="boil-rest" ng-controller="AppCtrl">
  • Updated app.js as follows:
angular.module( 'boil-rest', [
  'templates-app',
  'templates-common',
  'boil-rest.home',
  'boil-rest.about',
  'ui.state',
  'ui.route'
])

.config( function myAppConfig ( $stateProvider, $urlRouterProvider ) {
  $urlRouterProvider.otherwise( '/home' );
})

.run( function run ( titleService ) {
  titleService.setSuffix( ' | boil-rest' );
})

.controller( 'AppCtrl', function AppCtrl ( $scope, $location ) {
})

;
  • Updated home.js as follows:
angular.module( 'boil-rest.home', [
  'ui.state',
  'titleService',
  'plusOne',
  'restangular'
])

/** ...snip... */
.config(function config( $stateProvider ) {
  $stateProvider.state( 'home', {
    url: '/home',
    views: {
      "main": {
        controller: 'HomeCtrl',
        templateUrl: 'home/home.tpl.html'
      }
    }
  });
})

/** ...snip... */
.controller( 'HomeCtrl', function HomeController( $scope, titleService ) {
  titleService.setTitle( 'Home' );
})

;

Which all results in the following errors when I run grunt watch on the command line. Suggestions?


Running "karma:continuous" (karma) task
WARN [config]: config.configure() is deprecated, please use config.set() instead.
INFO [karma]: Karma v0.10.2 server started at http://localhost:9018/
INFO [launcher]: Starting browser Firefox
INFO [Firefox 23.0.0 (Mac OS X 10.8)]: Connected on socket xpe3c_8WRKWUXhvZecED
Firefox 23.0.0 (Mac OS X 10.8) AppCtrl isCurrentUrl should pass a dummy test FAILED
    Error: No module: restangular in /Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js (line 1211)
    setupModuleLoader/</module/<@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:1211
    ensure@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:1152
    module@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:1209
    createInjector/loadModules/<@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2904
    forEach@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:130
    loadModules@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2900
    createInjector/loadModules/<@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2905
    forEach@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:130
    loadModules@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2900
    createInjector/loadModules/<@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2905
    forEach@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:130
    loadModules@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2900
    createInjector@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2842
    workFn@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular-mocks/angular-mocks.js:1791

    Error: No module: restangular in /Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js (line 1211)
    setupModuleLoader/</module/<@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:1211
    ensure@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:1152
    module@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:1209
    createInjector/loadModules/<@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2904
    forEach@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:130
    loadModules@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2900
    createInjector/loadModules/<@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2905
    forEach@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:130
    loadModules@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2900
    createInjector/loadModules/<@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2905
    forEach@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:130
    loadModules@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2900
    createInjector@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2842
    workFn@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular-mocks/angular-mocks.js:1791

Firefox 23.0.0 (Mac OS X 10.8) home section should have a dummy test FAILED
    Error: No module: restangular in /Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js (line 1211)
    setupModuleLoader/</module/<@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:1211
    ensure@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:1152
    module@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:1209
    createInjector/loadModules/<@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2904
    forEach@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:130
    loadModules@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2900
    createInjector/loadModules/<@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2905
    forEach@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:130
    loadModules@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2900
    createInjector@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular/angular.js:2842
    workFn@/Users/brett/dev/gdwd/temp/boil-rest/vendor/angular-mocks/angular-mocks.js:1791

...
Firefox 23.0.0 (Mac OS X 10.8): Executed 5 of 5 (2 FAILED) (0.146 secs / 0.021 secs)
Warning: Task "karma:continuous" failed. Use --force to continue.

Aborted due to warnings.

lashex avatar Sep 09 '13 21:09 lashex

Hey,

Unfourtenately I don't have any example with ng-boilerplate. I know he was thinking of adding Restangular to it on the future.

But given the error, what I imagine is that your Restangular dependency didn't get added. I understand you downloaded the dependency with Bower. But did you add it into the HTML or into Karma to tell it to include Restangular after AngularJS and before the controllers? I think the error has to do with that.

mgonto avatar Sep 10 '13 03:09 mgonto

Well I've made some progress and no longer get the nasty karma:continuous error I posted previously.

After re-running bower install restangular --save-dev just to make sure everything was clean, I manually changed ngBoilerplate's build.config.js file with updated vendor_files list items of lodash.min.js and rectangular.min.js.

  vendor_files: {
    js: [
      'vendor/angular/angular.js',
      'vendor/angular-bootstrap/ui-bootstrap-tpls.min.js',
      'vendor/placeholders/angular-placeholders-0.0.1-SNAPSHOT.min.js',
      'vendor/angular-ui-router/release/angular-ui-router.js',
      'vendor/angular-ui-utils/modules/route/route.js',
      'vendor/lodash/dist/lodash.min.js',
      'vendor/restangular/dist/restangular.min.js'
    ],
    css: [
    ]
  },

Now I'll see how far I can get actually using Restangular to hit a REST API and render a response. Is it better to keep the Issue/question open for now to see if I can keep mining this path for an actual Restangular + ngBoilerplate success? If not feel free to close.

lashex avatar Sep 10 '13 06:09 lashex

I am using them both together without any problems.

svycka avatar Sep 10 '13 11:09 svycka

Hello @svycka - what API are you using the Restangular library against? I just started on this path but plan on trying to get both of these working against a Flask-based REST API

lashex avatar Sep 11 '13 04:09 lashex

that would be my API written with PHP and Zend Framework 2. But I can access any API I tried. You can even create json file response.json or something for backend.

svycka avatar Sep 11 '13 08:09 svycka

Hey guys,

Sorry I didn't answer before. Do you need my help here? Should I leave it open or closed?

Thanks!

mgonto avatar Sep 20 '13 18:09 mgonto

Closing. If more help is needed, please reopen!

mgonto avatar Oct 03 '13 20:10 mgonto

I now have everything working against a Flask based REST API. The issue turned out to be a CORS related one.

lashex avatar Oct 04 '13 04:10 lashex

Those are awesome news :). I'm glad.

Hope you're enjoying Restangular.

Closing the issue!

mgonto avatar Oct 04 '13 04:10 mgonto

For those hitting this error when using generator-ngbp, you need to add restangular to your package.json and _both_ restangular and its dependencies, lodash that is, to Grutfile.js.

This is what @lashex explains in his comment.

haizaar avatar Jun 15 '14 15:06 haizaar

@lashex I am having this problem as well. I have restangular 1.4.0 and I am using ngBoilerplate. I used to Yeoman to create the app. I have added the lodash and restangular dependencies to the following files but still have an error:

app/package.json app/Gruntfile.js app/build/karma-unit.js

And of course I am injecting it in my module.

Any chance you could post a Plunker of a complete example. I have searched everywhere with no results.

william-e-schroeder avatar Sep 05 '14 14:09 william-e-schroeder