Angular js Finding rendered Components - angularjs

I have used react and angular before but this is my first time using angular js.
I have spotted that you can render in html components similar to react and angular.
For instance the code I am trying to upgrade
<div ng-if="!userSubscription.compliance">
<user-premise-groups-selector premise-groups="premiseGroups"
select-or-deselect-premises="selectOrDeselectPremises(currentEvent, currentPremiseGroupId)"
select-or-deselect-all-premises="selectOrDeselectAllPremises(currentEvent)"
all-premise-groups-selected="allCompliancePremiseGroupsSelectedLocal()"
is-user-premise-group="isUserPremiseGroup(currentPremiseGroupId)">
</user-premise-groups-selector>
</div>
I am trying to access this component like you can in angular or react (looks as if the data is passed down similar to props in reactjs) but am unsure of how to do this. Do these components work similar to other front end libraries such as react and angular? And how do I jump into these so that I can change the outdated code.
Within components folder this component does not exist however.

These are called directives in angular as components are slightly diffrent

Related

How can I use ERB inside a React component? [Rails 6]

I have a project on Rails 6.
Started migrating it to React by using react-rails. However, there are still some components which I cannot migrate to React ATM due to time limitations.
I want to be able to use the old component (partial) in my React component.
e.g let's say I have a React component:
Component.tsx
export const Component = ({post}) => {
return <div>
<ShareButton post={post}/>
</div>
}
and somehow the ShareButton should contain this:
<%= render partial: 'posts/shared/share_post_btn', locals: {event: false, post: post} %>
I read that it may be possible by using .jsx.erb but I couldn't figure out how.
Would love to get some insights!
Thank you.
I'm afraid you'll be mixing build pipelines here. The .erb is parsed by the asset pipeline, which was the default for Rails <6 and still for CSS, but this doesn't work no longer by default for yarn/webpacker-based builds that Rails 6 favoured for JS output (Rails 7 choose a new path again, I'm sorry).
Also, as components typically have actions attached, I don't really see how a mixed Rails (static HTML) based approach could work.
A few ideas:
In the end, both Rails/ERB and React create HTML. Perhaps you can simply create the same HTML that your ShareButton creates with Rails as a temporary workaround? You'd share the CSS from the new front-end project, and you can slowly migrate rebuilding components in React (when you're thinking of building component library, make sure it works with stand alone HTML/CSS).
You can load static HTML in React using dangerouslysetinnerhtml; that might be a solution if you have complex prerendered text you want to load within a React component.
Load React client side (relatively slow); wouldn't really do this for production: How to perform import/export in client-side React JSX using Babel-Standalone
Do some parsing of the HTML received in React; and render components conditionally (this approach is a bit how Rails Turbo works; a more Rails-native answer to React, Vue and the like)
Push through: none of the 'solutions' above are really satisfying if you want to end up with a clean React version.
Roll back: why use react in the first place. React is just another fancy way of rendering HTML.

Getting elements by className in a React Function Component

For class Components in React, I could use
ReactDOM.findDOMNode(<instance-of-outermost-component>).getElementsByClassName('snap')
to get all the elements with className snap, but It doesn’t work with function components. How can I get all the elements with the same Classname in function components?
You should not really be accessing the DOM like that with React- unless you are using it within a testing framework. But even then you would not be accessing the DOM through ReactDom.
What are you trying to actually do when accessing the classes like that?
To apply changes in React you would want to be using state and then conditionally apply these to components. It seems like you are trying to apply a practice common in vanilla javascript development or even something like jQuery.
I think you would benefit from going through this demo of how state can be used: react state tutorial

What is the difference between angular component and React component?

Can someone explain that how the concept of components is different in Angular 8 and React? According to various tutorials I've watched, it says React components are reusable and can be rendered separately but it happens same in Angular as well. In file directory you have a main app component inside which you can create separate sidenav, header , footer components and use it whenever you like. It's isolated. So where's the difference? I've worked on Angular 8 previously and but new to React.
Angular and React are two differente technologies. Angular, a framework, with lots of built-in tools, and React a library (in my humble opinion, i would like to believe that you can call React a framework too) that has a popular rendering structure.
Angular and React components has the same concept, but obviously different implementations.
But for sure you can assume that components are made mainly for Code Reuse and Maintenance.

Migrating From Ember to React Page by Page Exploring Options

I want to move a big Ember v1.4.0 app to React. Instead of creating a new UI from scratch. I want to start building it in React my converting pages over slowly, essentially mixing React and Ember pages in one website.
Goal:
The above is my ultimate goal, but my first goal is is to create a single page in React that is called by Ember's router.
What I have tried so far: I wanted to create a React component in a ./templates/myFirstTestPage.handlebars because, as I understand it, the router.js calls a template file. But I am unsuccessful creating a React component in the handlebars file. Firstly, I cannot use <script> to import React because <script> does not work in handlebars. Secondly, I believe the handlebars is parsing the React app in an incorrect way. Actually, I don't really understand how, and in what order, these frameworks do the rendering.
Possible solutions (but I need implementation details):
Somehow create a React component in the template folder with the .handlebars extension.
Refer to the url of a React app in the handlebars of an Ember app
Have the Ember router map the url to a jsx file. This solution seems really viable to me. I think to myself that surely the creators of Ember must have thought that people might want to have their Ember app refer to some regular html file. Hence, I hope someone might have some knowledge whether this is possible or not.
Somehow create my own router that maps urls to particular files. If its a React component, then I'd map it to my jsx file, if not, I let Ember's router take care of the mapping. I don't really know how to implement a url mapping thing though.

Change browser title on route change in angular 1.5 component router

I am using angular 1.5 component router. I need to be able to change the title shown on the browser tab whenever there is a route change.
I have gone through the component router docs and googled it to many a websites but without any luck. The only way I can see to do it, is using vanilla JS inside each component's $onInit method.
I am looking out for an angular way of doing it and setting all the titles in one place. Please help.

Resources