What's difference Between module and component? - frontend

In front-end development, components(web components and reactive components) is the future, but how do you describe the difference between module and component? Is module categorized as only js files?

Related

Is it possible to export angular component as js and use as script in a legacy webpage?

I have an angular 8 project. I tried to export one component of it as
.js file.
Is it possible to export only one component as js file?
is it possible to embed it in a legacy webpage? perhaps as
in head.
Take a look at Angular Elements Overview. According to the documentation, it should be possible to export only components you want.
Angular elements are Angular components packaged as custom elements (also called Web Components), a web standard for defining new HTML elements in a framework-agnostic way.
Custom elements are a Web Platform feature currently supported by Chrome, Firefox, Opera, and Safari, and available in other browsers through polyfills (see Browser Support). A custom element extends HTML by allowing you to define a tag whose content is created and controlled by JavaScript code. The browser maintains a CustomElementRegistry of defined custom elements, which maps an instantiable JavaScript class to an HTML tag.

Using Vue Material UI Components with Bootstrap Layout

I am starting my first Vue 2 project and would like to mix Vue Material Components with Bootstrap layout. I have enough experience with Angular Material components to know that mixing them with Bootstrap causes problems. I would like to use Vue Material and integrate it with a Bootstrap theme template. Is this going to be a problem? Thanks in advance.
No problem, you can install the material and the bootstrap without a problem, just be careful when calling the styles, because whoever is last

Prismic.io in Angular 2

I'm trying to find a way to import the Prismic.io javascript kit in my Angular 2 project.
Is there a way to do so ? I tried to understand their Angular2-starter but it's not documented to do it on an existing project.
I want to know if there is a way to import node modules directly into Angular2 ?
Thanks in advance !
You need to be more specific, what does it mean import modules directly into angular 2?
First, to have common ground about modules:
Modules are a core feature of javascript, either natively in ES6 or using bundlers (e.g WebPack, SystemJS, etc...)
Importing a modules is not related to Angular 2
As for Angular 2, if by using directly you mean being able to inject service via the dependency injection then this is just a configuration operation done in angular.
In the case of an external, 3rd party, NON Angular library you might want to wrap it with an angular service which is then injected.
The starter project you linked to does so, it defined a prismic-service class that wrap the original prismic library so you only work against the wrapper class.
You can extend this class to support more features as you go.
Some notes on extending 3rd part libraries in angular 2 vs angular 1:
AngularJS (1) developers approach 3rd party libraries with caution. Since AngularJS has an internal change detection mechanism that Angular has to manage, execute and control. Any 3rd party library that modifies data that directly or indirectly effects the UI must also trigger the internal change detection in angular.
In Angular2 change detection is triggered by generic async operations such as events, user interactions, etc... Angular does not manage it directly, it is triggered automatically as if it was magic. This is possible due to the help of Zones which is both a concept and a library. Angular implements NgZone.
Basically it means that you can use prismic directly or as a wrapped angular service, it doesn't matter, it will just work.
I guess that most of your questions will focus on integration, which is how to take the data from the API and make a UI out of it.
The prismic Development kit provides a REST API for retrieving metadata about UI elements and data that they contain.
The client (in a SPA, like angular 2) needs to display actual UI components from the metadata.
In other words you need to build Angular 2 components that correspond to the components in prismic.
A common JavaScript library that builds a UI from prismic REST API data will not work here. It will generate HTML code that is not part of the angular application and does no participate in change detection, lifecycle hooks and routing.
All components in angular must be compiled first, at the bootstrap or at build if offline compiler is used.
The minimal approach is to get the HTML markup from the server and inject it into an angular component acting as a wrapper. This allows control over the lifecycle of a page and used for routing, page transition animation etc...
The starter project provides such a wrapper called DocumentPage. The DocumentPage has logic to download it's content (via route parameters) from prismic and display it as raw HTML. See here
The html markup retrieved from prismic is NOT bindable and you can't apply change detection and expressions in it. If you split it into chunks you can apply some angular magic in between.
So, it's quite simple actually, the starter project is a simple wrapper around the prismic framework in both API and UI. Angular has a small part in the application as it acts as a simple wrapper/container. The actual content is driven by prismic. I don't see benefits using angular with such approach, it doesn't do any harm but it's not really an angular app.
A proper angular2 prismic app would be built upon pure metadata representation of components which are implemented in angular as angular components. It is quite an advanced app that requires dynamic component creation as well as advanced routing implementation with lazy loading (to introduce new components on the fly).

How to use SVGs and image fallbacks with ReactJs?

I am currently using ReactJs for one of my project. Since we all thing in terms of components when it comes to ReactJs, how do we approach having SVGs/fallbacks in React application?
Do we build component for each SVG? or is there a different way you React users build them? I just want to approaching it with the best practise!
I would be really happy if someone helps :)
Have a look at the material-ui library's approach to SVG support. They have a SvgIcon component which you should be able to reuse. Their approach is having the common implementation separated out in the SvgIcon component and then having individual component wrappers for each unique SVG icon.

how dynamically initialize components of materialise design lite (google) for SPA?

how dynamically initialize components of materialise design lite (google) for SPA ? As I am dynamically initializing the components in a view the JS is not initializing. As i have tried with many solutions using componentHandler.
To initialize the javascript components of MDL not starting to window.load you must update the DOM component:
componentHandler.upgradeDom();
For more information
https://github.com/google/material-design-lite/issues/871

Resources