30.05.2017 Views

Web_Designer_Issue_262_2017

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Developer tutorials<br />

What’s new in Angular 4?<br />

7. Unmet Peer Dependencies<br />

Peer dependencies are for managing projects that<br />

have packages relying on diferent versions of the<br />

same dependencies. You have to add these manually<br />

to your package.json file. The peer dependencies that<br />

we need for Flower Shop include older versions of<br />

package.json<br />

For ongoing Angular projects, your package.json<br />

will need monitoring. If you update any part of your<br />

app, subsequent errors are likely to be solved by<br />

checking your dependency versions. The best place<br />

to check this is in terminal errors on npm install.<br />

@angular/{core,http}, rxjs and zone.js. Review the errors in<br />

the terminal output and add each missing dependency<br />

to package.json.<br />

"peerDependencies": {<br />

"@angular/core": ">= 2.0.0",<br />

"@angular/http": ">= 2.0.0",<br />

"rxjs": "^5.0.0",<br />

"zone.js": "0.7.8"<br />

},<br />

8. Watch out for custom<br />

component name changes<br />

Our Flower Shop app is making use of an open-source<br />

custom component called ng2-modal. However, the<br />

author has since updated their naming convention to<br />

ngx-modal. We need to modify our dependency name<br />

and ng-module imports accordingly.<br />

package.json:<br />

"dependencies": {<br />

[...]<br />

"ngx-modal": "0.0.25",<br />

[...]<br />

},<br />

app/app.module.ts:<br />

import { ModalModule } from 'ngx-modal';<br />

9. Check versions<br />

Our custom modal component also needs updating<br />

to a more recent version, so be sure to update it<br />

with npm.<br />

$ npm install ngx-modal@latest --save<br />

10. Check your work<br />

Now that we’ve patched up our dependencies, it’s a<br />

good idea to clear node_modules and build it again<br />

from our package.json. If all goes well you should<br />

have a clean build! If you don’t, something may still<br />

be missing in your dependency versions. Take<br />

another look.<br />

$ rm -rf node_modules/<br />

$ npm cache clean<br />

$ npm install<br />

$ ng serve --open<br />

11. View engine<br />

Let’s see what new features we can use in 4.0. The new<br />

view engine compiles to a much smaller bundle, meaning<br />

Top<br />

Our custom modal module needs renaming to match new versions of<br />

angular naming conventions<br />

Above<br />

Our build should succeed now that we’ve corrected our dependency<br />

version discrepancies<br />

Right<br />

Make sure all third-party and custom-dependency versions are up to date!<br />

Use @latest or one of the stated ‘valid install target’ version numbers<br />

82

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!