These are chat archives for ngUpgraders/ng-forward

15th
Dec 2015
David Gang
@david-gang
Dec 15 2015 14:29
hi @timkindberg
regarding #120
i disagree with the label
this is not an enhancement request
this is one of the major purposes of ng-forward
Those who are actively migrating to Angular 2, who'd like to use ng-forward as the first step in their migration strategy. Once you've used ng-forward to update all the syntax in your project, you can then optionally use ng-upgrade or go straight to Angular 2.
i have a workaround for using angular2 objects with ng-forward
let's say i have a component Logo
Brandon
@brandonroberts
Dec 15 2015 14:33
You used a bundle to downgrade your ng2 component?
David Gang
@david-gang
Dec 15 2015 14:33
yes
and then i register it with a string
module.directive('logo', Logo)
angular,module('upgrade-module').directive('logo', Logo)
and then in the ng-forward component i use the 'upgrade-module' as provider
Brandon
@brandonroberts
Dec 15 2015 14:34
Yep
David Gang
@david-gang
Dec 15 2015 14:35
now i just need a workaround to use ng-forward modules in angular2
how do i accomplish this?
Brandon
@brandonroberts
Dec 15 2015 14:36
All you need for ng1 to ng2 is to upgrade the component name in your ng2 directives array
David Gang
@david-gang
Dec 15 2015 14:36
i think this should also be possible
i can get the name of the directive
with the getInjectableName
and then upgrade this
is this a good idea?
Brandon
@brandonroberts
Dec 15 2015 14:36
@Component({
   selector: ‘name’,
directives: [adapter.upgradeNg1Component(‘name’)]
})
class Ng2Component {}
David Gang
@david-gang
Dec 15 2015 14:37
yes :)
ok
so i have a workaround
it is not especially nice
but will serve my purpose
who says that everything in life has to be nice :-)
thanks @brandonroberts
Brandon
@brandonroberts
Dec 15 2015 14:38
Yea, you will still have to remove some ng-forward parts when you completely migrate over
:+1:
Tim Kindberg
@timkindberg
Dec 15 2015 15:24
@azangru nativeElement is one of the jqlite extensions that we've added. We are adding it to the jq object, be it angular's jqlite or jquery if you have it loaded.
@david-gang I know it's not a request for enhancement but I think we need to make it one so I did. We need better support for using the two libraries together.
I think it would be cool if we downgraded the ng2 components automatically for you
We could try to detect the metadata on the Component and see if its from ng2
or something :P
David Gang
@david-gang
Dec 15 2015 15:28
that's awesome :clap:
Tim Kindberg
@timkindberg
Dec 15 2015 15:28
And maybe something to easily upgrade as well
MyNgForwardComponent.upgrade()
David Gang
@david-gang
Dec 15 2015 15:29
this would be great
Tim Kindberg
@timkindberg
Dec 15 2015 15:29
@Component({
   selector: ‘name’,
directives: [MyNgForwardComponent.upgrade()]
})
class Ng2Component {}
yeah not sure but we can give it a shot!
or hell maybe we can ask ngUpgrade to have some compatibility with US!
David Gang
@david-gang
Dec 15 2015 15:30
this would be really nice
yes :-)
Tim Kindberg
@timkindberg
Dec 15 2015 15:30
they maybe could detect for an ngforward component automatically
good thoughts
David Gang
@david-gang
Dec 15 2015 15:31
maybe pete could help us here ?
Tim Kindberg
@timkindberg
Dec 15 2015 15:31
Yeah let's get farther on our own first and then we'll ask them
David Gang
@david-gang
Dec 15 2015 15:31
great :-)
Tim Kindberg
@timkindberg
Dec 15 2015 15:31
thanks for all your help on this david
David Gang
@david-gang
Dec 15 2015 15:31
:-)
Andrey Azov
@azangru
Dec 15 2015 18:32
@timkindberg, here is a gist with a more detailed version of the question related to the Uncaught TypeError: Cannot redefine property: nativeElement problem: https://gist.github.com/azangru/33c1d9f65cf29eea7c9a
Gitter’s mardown editor didn't seem to like me at the moment and garbled up the code formatting when I was writing the question here :-(
Andrey Azov
@azangru
Dec 15 2015 20:43
Ok, I realized that I was stupid, updated Karma’s config and got rid of the above error.
Andrey Azov
@azangru
Dec 15 2015 23:15

Argh! Back to that same error again!
Tests run fine while I run them in one file. The second I add another spec file and import another service for testing, I get the error.

Example:
1) start testing some service, for example there is an ApiService in my app.

import { providers } from 'ng-forward/testing';
import ApiService from '../api-service';

everything goes fine

2) proceed to testing another service in another file, for example there is also an AuthService in my app:

import { providers } from 'ng-forward/testing';
import AuthService from '../auth-service';

the second I try to import the second service in that other file, I get:

  Uncaught TypeError: Cannot redefine property: nativeElement
  at blah-blah/src/client/common/tests/auth-service-spec.js:3211

When I comment out that import statement for the other service, the error disappears, but of course then there is no way for testing.

I am using Webpack to build the project.