evertonrobertoauler / cli-universal-demo

80 stars 18 forks source link

Import global extneral dependency (i.e google maps) and using in input decorattor #25

Closed ahmed-anas closed 7 years ago

ahmed-anas commented 7 years ago

Thanks for this. Unfortunately I have a small issue. Installing an external dependency (i.e google maps) using npm install -S @types/google-maps and then using it as an input decorator @Input() foo : google.maps.Map gives the error:

ReferenceError: google is not defined
    at Object.c (C:\work\tests\cli-universal-demo\dist\server.js:2601:31)
    at __webpack_require__ (C:\work\tests\cli-universal-demo\dist\server.js:20:30)
    at Object.c (C:\work\tests\cli-universal-demo\dist\server.js:3461:23)
    at __webpack_require__ (C:\work\tests\cli-universal-demo\dist\server.js:20:30)
    at Object.c (C:\work\tests\cli-universal-demo\dist\server.js:7441:20)
    at __webpack_require__ (C:\work\tests\cli-universal-demo\dist\server.js:20:30)
    at Object.<anonymous> (C:\work\tests\cli-universal-demo\dist\server.js:3550:10)
    at __webpack_require__ (C:\work\tests\cli-universal-demo\dist\server.js:20:30)
    at Object.<anonymous> (C:\work\tests\cli-universal-demo\dist\server.js:7566:37)
    at Object.<anonymous> (C:\work\tests\cli-universal-demo\dist\server.js:7589:30)

The server.js file at that line looks like this:

__decorate([
    core_1.Input(),
    __metadata("design:type", google.maps.Map)
], AppComponent.prototype, "f", void 0);
AppComponent = __decorate([
    core_1.Component({
        selector: 'app-root',
        templateUrl: './app.component.html',
        styleUrls: ['./app.component.scss']
    })
], AppComponent);

Note that only using as input decorator (for now at least) gives the error. Using as input to functions or inside functions doesn't give any errors.

evertonrobertoauler commented 7 years ago

Look this example:

https://gist.github.com/evertonrobertoauler/aed3f2f50694c524d880ad1a5c5838f7

Check if you are running on the browser before trying to use the google maps api.