These are chat archives for AngularClass/NG6-starter

1st
Jan 2016
Andrew Lombardi
@kinabalu
Jan 01 2016 16:21
is there any trick to getting Rectangular to work with this starter?
Andrew Lombardi
@kinabalu
Jan 01 2016 16:47
or Restangular rather (stupid autocorrect)
Sergey Protko
@fesor
Jan 01 2016 20:00
npm install restangular
in module that uses it just import ‘restangular’
there is nothing special about any third party libraries except that we are using npm as package manager and webpack as bundler (or jspm and system.js if you intererested in)
Andrew Lombardi
@kinabalu
Jan 01 2016 23:18
@fesor ok, i have restangular installed, and import ‘restangular’ in the the plain let’s say ‘home.js’ file, and then how to reference it in the controller? does it just go into the constructor?
Sergey Protko
@fesor
Jan 01 2016 23:19
yep, you pass restangular to your controller constructor and just uses it.
Andy Brown
@brownish
Jan 01 2016 23:19
make sure you inject it into the home.js angular.module
like you normally would
Sergey Protko
@fesor
Jan 01 2016 23:19
not injected but specified dependency from restangular module
Andy Brown
@brownish
Jan 01 2016 23:21
import restangular from 'restangular';
let dataModule = angular.module('app.common.data', [
      'restangular'
    ])
i have it like so one place
Sergey Protko
@fesor
Jan 01 2016 23:21
yep, seems to be ok
p.s. I don’t recommend you to use restangular dirrectly in component’s controllers. Consider to use stateless/stupid UI components in future and pass state to them from above (from state resolvers for example).
you can read more about stateless vs stateful components in the internet
Andrew Lombardi
@kinabalu
Jan 01 2016 23:22

import uiRouter from 'angular-ui-router';
import aboutComponent from './about.component';
import restangular from 'restangular';

let aboutModule = angular.module('about', [
uiRouter,
'restangular'
])

just as an example, the above snippet and I get a nasty javascript error
and restangular is definitely in node_modules
Andy Brown
@brownish
Jan 01 2016 23:23
i only use it in one service, then the states' resolves pulls data and injects in into the components
Sergey Protko
@fesor
Jan 01 2016 23:23
@kinabalu could you provide an error?
Andrew Lombardi
@kinabalu
Jan 01 2016 23:23
oh wait, i think lodash or underscore might be required by restangular
Sergey Protko
@fesor
Jan 01 2016 23:24
yep
it uses lodash for some reason
Andy Brown
@brownish
Jan 01 2016 23:24
yeah lodash is, but i dont think you need to import it anywhere
Andrew Lombardi
@kinabalu
Jan 01 2016 23:24
Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:modulerr] Failed to instantiate module app.components due to:
Error: [$injector:modulerr] Failed to instantiate module about due to:
Error: [$injector:modulerr] Failed to instantiate module restangular due to:
ReferenceError: _ is not defined
Sergey Protko
@fesor
Jan 01 2016 23:24
nope, restangular doesn’t have any module system and relies on lodash global variable
I can recommend you to wrap restangular to your ES6 module:
Andy Brown
@brownish
Jan 01 2016 23:26
how do you do that?
Sergey Protko
@fesor
Jan 01 2016 23:27
// 3rdparty/restangular.js
import ‘lodash’;
import ‘restangular’;

export default ‘restangular’;
// components/about/about.js

import restangular from ‘myapp/3rdparty/restangular’

angular.module(‘app’, [restangular])
but you may consider this as an overhead)
Andy Brown
@brownish
Jan 01 2016 23:27
ah okay
i've only got it importing into the one component
Sergey Protko
@fesor
Jan 01 2016 23:28
this is useful if you have a lot of this “bad” dependencies)
Andy Brown
@brownish
Jan 01 2016 23:28
oh so it doesn't get exposed globally?
Sergey Protko
@fesor
Jan 01 2016 23:29
no, it just allows you to move this import/dependency hell out of your application files
mgonto/restangular#1284
Andy Brown
@brownish
Jan 01 2016 23:30
ah okay gotcha
Andrew Lombardi
@kinabalu
Jan 01 2016 23:31
that’s cool. are there any examples of using state resolvers to pass back state using this NG6-Starter? JS isn’t a strong suit, used to more python, java, etc
@fesor you use ng-redux, right?
Andrew Lombardi
@kinabalu
Jan 01 2016 23:32
ah ok, i’ve definitely done that before, just wsa using ngbp before.