Why mat-icon doesn't work in certain files? - html

I want to use mat-icons in my Angular project.
In src/app/files/files.html, I can use mat-icons, however, in src/app/files/public-file/public-file.html, mat-icon doesn't display.
Why is this happening?

I just forgot to import the class in app.module

Related

My css classes in react are afecting diferent pages

Hello guys so this is my problem , i have one page in react called 'Page1.js' that has one <div className='container' >, and this Page1.js imports css style from another file called page1.css with
import './page1.css'.
in this page1.css i make one class called '.container' that has properties like
.container {
background-color:blue
well so far there is no problem, my div is with it's background blue as it supposed to be.
The problem starts when i make another page like 'page2.js' and i make another div with a class having the same name...
So for example if i make one div <div className='container' > in this new 'page2.js' automatically this div will have it's background blue. But i didn't import the file 'page1.css' on my 'page2.js'.
My questions are:
why my page2.js that has no import for my file page1.css is getting the properties for the classes ?
Is there anyway for me to be using classes css with the same name on diferent jsx pages and the classes not be overwriting each other ?
for to escape from this problem now, for each class that i create i put the name of the page in the class like-------------> page1-container {background-color:blue} is that the right thing to do ?
This is because CSS is globally applied when you called import from the previous file.
The import is just a hint for webpack (or maybe some other bundler) to create a separate css file.
To make it private and only available for the file with the import you have to use css.modules <assuming you're using Create react app>
Try to make an experiment. Rename the file from page1.css -> page1.module.css
and import the style from this file like this:
import styles from "./page1.module.css"
and apply it:
<div className={styles.background}>Test </div>

Changing fxFlex value in the Component with "setAttribute('fxFlex', '25%')" not Working in Angular 6

I'm using flexLayout module (see more in https://github.com/angular/flex-layout also in https://alligator.io/angular/flex-layout/) to build responsive div in my Angular application and I want to set the value of fxFlex attribute from my Angular Component.
code in the component.ts:
const nav = document.getElementById('nav2'); nav.setAttribute('fxFlex', '5%');
code in the html page:
<div fxLayout>
<div id="nav2" fxFlex="25%" class="col-md-2.5 bg-white p-1">hello</div>
<div id="nav1">word</div></div>
the code should normally should change the size Layout to 5%, but it's not the case, when i inspect the page I found that the attribute has been change but the layout still the same, oddly when i change it manually in the html code to 5%, i get the result that i wanted.
I'm using Angular 6, and Typescript 3.1.1
Please, If there is any suggestion, do not hesitate.
Thank You !
the code should normally should change the size Layout to 5%
No it should not.
Angular directives are ussed in Typescript, or in a pre-build context.
When you write
document.getElementById('nav2'); nav.setAttribute('fxFlex', '5%')
You instruct the Javascript, that has been compiled from Typescript (so in a post-build context) to get the element and add an Angular directive to your attribute.
The thing is, the code is already compiled, so you can't add typescript to Javascript, otherwise you would have to compile it again (and I'm not even sure you can do that).
I suggest you learn about angular features and how it works before using it. Also, consider posting a Minimal, Complete, and Verifiable example if you want someone to offer a solution adapted to your case.
In angular, you need to use the renderer2 to setAttribute dynamically.
Example:
HTML
<div #myDiv id="nav2" fxFlex="25%" class="col-md-2.5 bg-white p-1"></div>
component.ts
import {ElementRef,Renderer2} from '#angular/core';
...
export class MyComponent implements AfterViewInit {
#ViewChild('myDiv') el:ElementRef; // get the refernce of dom element.
constructor(private rd: Renderer2) {}
ngAfterViewInit() {
// Update dom after view initialized.
this.renderer2.setAttribute(this.el.nativeElement, "fxFlex", "5%");
}
}

How do I import css style from ts to less in angular cli?

The reason why I need to insert styles from .ts file into less: I have a website and something like content manager panel where you can set the color of buttons for it.
Of course I can use this css variable in my html templates like:
[style.color]="colorVar"
but maybe there is exist some better solution?
you can use ::ng-deep to penetrate into some component and change the styles.
some-component-selector ::ng-deep selector-inside-of-that-some-component {
//write the sytles here
}

Bootstrap with Angular 2+

Im trying to use a primary button from bootstrap in my Angular module. But it seems to not work.
Heres what I've done so far.
npm install ngx-bootstrap --save
Added bootstrap module and imports.
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
import { TooltipModule } from 'ngx-bootstrap/tooltip';
import { ModalModule } from 'ngx-bootstrap/modal';
imports: [
BrowserModule,
BsDropdownModule.forRoot(),
TooltipModule.forRoot(),
ModalModule.forRoot(),...]
exports: [BsDropdownModule, TooltipModule, ModalModule]
Now in the Module I use this code for a button:
<button type="submit" class="btn btn-primary">Submit</button>
but the button is still the standard html button. Not a blue submit button. Did I forget any steps when importing bootstrap. In the node_modules structure I can find bootstrap in there with the necessary .js and .css files.
Thanks for help.
You don't need to import modules, instead you need to attach styles from bootstrap. import them in the styles.css file or configure in the styles section of the angular.json file
"styles": [
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
]
or your relative/absolute path
Looks like in your case bootstrap is just about styling. Pure CSS styling of your HTML elements. Ngx-bootstrap it is about Angular components(the way you are decomposing your application). It's just like regular bootstrap with a jquery for interactivity but in an Angular world.
To get just bootstrap styles in your application you need to run command:
npm install bootstrap
Then put these source files into angular-cli.json:
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css"
]
And rebuild you project.
We have two options to import the CSS from Bootstrap that was installed from NPM. One by configuring in angular.json and second by importing directly in src/style.css or src/style.scss. You can go through this https://loiane.com/2017/08/how-to-add-bootstrap-to-an-angular-cli-project/#3-importing-the-css and learn more about how to do that.

Why doesn't individual styling of a react component instance work?

I'm using the following instance of a react component in a view:
<Jumbotron>
Lot's of important content
</Jumbotron>
I want an individual style (i.e. a different background image for this instance. So this doesn't work:
<Jumbotron className="individual">
Lot's of important content
</Jumbotron>
Wrapping the instance in a div also doesn't work. How can I do this with simple markup and CSS so that I can simply style the individual class in CSS? AFAIK properties won't help to customize instances...
You can either pass in the style attribute or you can pass through the className attribute in the same way
<Jumbotron className="background--black">
And have your component like this -
const Jumbotron = ({className}) => {
<div className={className}>
Here is the jumbotron
</div>
}
export default Jumbotron
And import a css file that has that class in, if you're using className. But I would probably recommend just using style attribute if it's a one off.