项目作者: omarbelkady

项目描述 :
AngularJS
高级语言: HTML
项目地址: git://github.com/omarbelkady/AngularJS.git
创建时间: 2020-10-07T00:32:13Z
项目社区:https://github.com/omarbelkady/AngularJS

开源协议:

下载


Angular JS

Expressions in Angular

  • An Expression is simply a JS expression wrapped in curly braces and is outputed to the DOM
  • Expressions can be:
    • Some Computation Logic
    • Literals
    • Operators
    • Variables
  1. <!DOCTYPE html>
  2. <html >
  3. <head>
  4. <script src="~/Scripts/angular.js"></script>
  5. </head>
  6. <body >
  7. <div ng-app ng-init="sayHi='Hi There Everyone!'; luckyNum= 13; rate = 10.5; time= 11; myArr = [458, 812]; individual = { fName:'Omar', lName :'Belkay'}">
  8. {{ (luckyNum * rate * time)/100 }}<br />
  9. {{myArr[1]}} <br />
  10. {{individual.fName + " " + individual.lName}}
  11. </div>
  12. </body>
  13. </html>

ng-init directive

  • I use the ng-init directive to declare variables within my application and they can be of any datatype

NO-FLY ZONES FOR EXPRESSIONS

  • DeniedIcon
  1. Contain a conditional
  2. Have a loop
  3. Exceptions
  4. RegEx
  5. Declare Functions
  6. Have A Comma
  7. Have A Void
  8. Have the return keyword in them

Install Angular CLI

  1. npm i -g @angular/cli

How To Create An Angular Application Using The Angular CLI

  1. ng new nameofangapp

Flags When Creating An Angular App

  • —verboase=true Telling Angular to output more info to the console
  • —skipTests=true Telling Angular to not generate test files for my project
  • —skipGit=true Telling Angular to not initialize a Git Repo for my project
  • —routing=true Telling Angular that I want routing in my app and to have it listed in my modules

Project Structure

  1. ├── README.md
  2. ├── /node_modules ======> 3rd party libs are installed here that we use in my app
  3. └── /src
  4. └── /myapp ======> All the files necessary to generate the UI of my app are here
  5. | ├── myapp-routing.module.ts
  6. | ├── myapp.component.css ======> CSS Stylesheet for the root component
  7. | ├── myapp-component.html ======> Create the html file for me
  8. | ├── myapp.component.spec.ts ======> Unit tests for the root component
  9. | ├── myapp.component.ts ======> Definition of module and properties
  10. | └── myapp.module.ts ======> Root Component i.e. App.js in ReactJS
  11. ├── /assets ======> Static files i.e. images, fonts, etc.
  12. ├── /environments ======> configuration for development and production environments
  13. | ├── environment.prod.ts
  14. | └── environment.ts
  15. ├── favicon.ico
  16. ├── index.html ======> Bootstraps my app
  17. ├── main.ts ======> Main entry point of your Angular app tells Angular to start my app
  18. ├── polyfills.ts
  19. ├── styles.css ======> Global styling
  20. └── test.ts ======> Unit Tests
  21. ├── angular.json ======> Defines structure to my angular application
  22. ├── karma.conf.js ======> Test runner file
  23. ├── package-lock.json ======> Gives Angular Details in regards to the version for all the packages in node_modules dir
  24. ├── package.json ======> Configures all your npm package dependencies
  25. ├── README.md ======> Documentation
  26. ├── tsconfig.app.json
  27. ├── tsconfig.json ======> Typescript configuration file... Gives instructions to the typescript compiler
  28. ├── .browserslistrc
  29. ├── .editorconfig
  30. └── .gitignore ======> List the files you do not want Git To Track Here

Fire Your Angular App in The Browser

  1. ng serve

How To Create A Component In Angular

  1. ng generate component navbar

2nd Way ofHow To Create A Component In Angular

  1. ng g c navbar

Dependency Injection In Angular

  • @ Injectable Decorator tells Angular that this specified Service Class should be visible to everyone
    • within your Application.
  • Since Components consume services
  • I need Dependency Injection to give my component all the power my service has for functionality purposes

Good Practices

  • ALWAYS keep your Components and Services Separate
  • Failure to do so will require you to FIRST declare your Service THEEEN your Component
    • IF you fail to follow this order it results in:
      • RUNTIME NULL REFERENCE ERROR