WEB - AngularJS and Typescript

news/2026/1/17 19:01:38/文章来源:https://www.cnblogs.com/Mattcoder/p/9297914.html

Source code https://github.com/mattcoder2017/CoreTypescript/tree/master/WebApplication1

AngularIO:  https://angular.io/

Nodejs vs angular compatiblity matrix

https://angular.io/guide/versions

ngx bootstrap & modal

https://valor-software.com/ngx-bootstrap/#/components/modals?tab=overview

Angular Material Caroussel

https://material.angular.io/guide/getting-started

Ngx datatable

https://swimlane.github.io/ngx-datatable/

Material Carousel

https://gbrlsnchs.github.io/material2-carousel/

nvm in linux https://tecadmin.net/install-nvm-centos-8/#:~:text=A%20shell%20script%20is%20available%20for%20the%20installation,creates%20a%20.nvm%20directory%20under%20the%20home%20directory.

nvm to switch between nodejs version

  1. Install Chocolatey (Package Manager): nvm can be installed on Windows using Chocolatey, a popular package manager for Windows. If you don't already have Chocolatey installed, follow these steps to install it:

    Open a PowerShell terminal as an administrator (right-click on PowerShell and select "Run as administrator") and run the following command:

    powershell
    Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

    This command will download and install Chocolatey.

  2. Install nvm using Chocolatey: After Chocolatey is installed, you can use it to install nvm. Open a new PowerShell terminal (as administrator) and run the following command to install nvm:

    powershell
    choco install nvm
  3. Verify nvm Installation: After the installation is complete, close and reopen your PowerShell terminal (or open a new one) to ensure the changes take effect. To verify that nvm is installed, you can run:

    powershell
    nvm version

    You should see the installed version of nvm displayed.

  4. Install Node.js Versions with nvm: Now that nvm is installed, you can use it to install specific Node.js versions. For example, to install Node.js version 14, run:

    powershell
    nvm install 14

    To install Node.js version 16, replace 14 with 16 in the command above.

  5. Switch Between Node.js Versions: To switch between installed Node.js versions, you can use the nvm use command followed by the version number. For example, to use Node.js version 14, run:

    powershell
    nvm use 14

Setup Angular in windows https://angular.io/guide/setup-local

https://unpkg.com/browse/@angular/core@15.2.0/package.json, 

Angular 15.2 supported by NodeJs version of 14.20, 16.13 etc

Udemy: https://commscope1.udemy.com/course/learn-to-build-an-e-commerce-app-with-net-core-and-angular/learn/lecture/18137468#overview
TypeScript:

Difference - Class syntax

 

tsconfig.json is needed at root level, sourceMap is used for browser debugging just like managed code

 Run commandline to get the angular cli

npm install -g @angular/cli

3 major commands to be used -new -build - serve

//alternatively you can use npm run ng <command>

//Or add the npm to enviornemental variable PATH

 

 

Use ng generate to add component. service automatically and they are referenced at appmodule.ts without manual effort.

https://github.com/angular/angular-cli/wiki/generate-component 

D:\SourceCode\FromAppToK8S2022\AngularNetCoreProj\ClientApp\src\app\product>ng g c productmodify --module=Product.module
CREATE src/app/product/productmodify/productmodify.component.html (32 bytes)
CREATE src/app/product/productmodify/productmodify.component.spec.ts (677 bytes)
CREATE src/app/product/productmodify/productmodify.component.ts (297 bytes)
CREATE src/app/product/productmodify/productmodify.component.css (0 bytes)

Create a subfolder right under root level name "ClientApp"

Move angular.json and tsconfig.json under root level to replace existed ones

Move everyfile from the src to ClientApp

 

Anyway, actually we are just interested in moving the package.json that download each angular module copy over to one in .net project, so that NPM under 

dependency will grab

{"name": "dutch-app","version": "0.0.0","scripts": {"ng": "ng","start": "ng serve","build": "ng build","test": "ng test","lint": "ng lint","e2e": "ng e2e"},"private": true,"dependencies": {"@angular/animations": "^6.1.0","@angular/common": "^6.1.0","@angular/compiler": "^6.1.0","@angular/core": "^6.1.0","@angular/forms": "^6.1.0","@angular/http": "^6.1.0","@angular/platform-browser": "^6.1.0","@angular/platform-browser-dynamic": "^6.1.0","@angular/router": "^6.1.0","core-js": "^2.5.4","rxjs": "~6.2.0","zone.js": "~0.8.26"},"devDependencies": {"@angular-devkit/build-angular": "~0.8.0","@angular/cli": "~6.2.5","@angular/compiler-cli": "^6.1.0","@angular/language-service": "^6.1.0","@types/jasmine": "~2.8.8","@types/jasminewd2": "~2.0.3","@types/node": "~8.9.4","codelyzer": "~4.3.0","jasmine-core": "~2.99.1","jasmine-spec-reporter": "~4.2.1","karma": "~3.0.0","karma-chrome-launcher": "~2.2.0","karma-coverage-istanbul-reporter": "~2.0.1","karma-jasmine": "~1.1.2","karma-jasmine-html-reporter": "^0.2.2","protractor": "~5.4.0","ts-node": "~7.0.0","tslint": "~5.11.0","typescript": "~2.9.2"}
}
package.json

 Modify angular.json file to allow cli build command to dump root level ts based ts or html files to the directory under wwwroot

 

Run ng build to flush the files to dist according to angular.json

main.ts will import app.module and in turn import app.component

  •  Move the UI to external template

  • Create shop component to contains product and cart componenet

  • Create Entity Framework entity and repository
    • Add Entities
  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;namespace ASPCoreAngular.Persistence.Entity
    {public class Order{public int Id { get; set; }public DateTime Date { get; set; }public IList<OrderItem> OrderItems { get; set; }}
    }
    Entities
    • Add dbcontext class,  be aware that data base table naming should follow - entityname+'s', e.g. Order.cs -> Orders table in database
  • using ASPCoreAngular.Persistence.Entity;
    using Microsoft.EntityFrameworkCore;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;namespace ASPCoreAngular.Persistence
    {public class CoreContext : DbContext{public DbSet<Product> Products { get; set; }public DbSet<Order> Orders { get; set; }public DbSet<OrderItem> OrderItems { get; set; }public CoreContext(DbContextOptions<CoreContext> options): base(options){}protected override void OnModelCreating(ModelBuilder modelBuilder){modelBuilder.Entity<Order>().HasMany(e => e.OrderItems).WithOne(e => e.Order).HasForeignKey(e => e.OrderId);base.OnModelCreating(modelBuilder);}}
    }
    DBContext
    • Add dbcontext object to service registry at startup.cs

  • Create Web API to fetch data

ASP CORE doesnt requires webapi route config like in .net 4.5, simply create Controller -> ApiController and everything is ready to go

 

  • Create typescript entity type to ensure typesafe

Use  https://csharptotypescript.azurewebsites.net/   or  http://json2ts.com/ to obtain the typscritp type

Using https://json2csharp.com/ to convert json object to c# type

 

  • Create share / dataservice to get the data 

Service (Injectable)

providedIn specify the module this service will be eligible to inject, 'root' is referring to the base module i.e. appmodule.

Unlike other components or module when the routing engine navigate the user to different view, their instances and cached data will be clear from memory, base module and its data will not be terminated and clear from the memory during routing.

 

 

  • Create share / dataservice / Order to coordinate the addcart action
  • Routing
  • Checkout page
  • Error popup using toastr https://github.com/scttcper/ngx-toastr

    • npm install ngx-toastr --save
  • Loading popup using ngxspinner https://www.npmjs.com/package/ngx-spinner#installation
    • Choose a spinning style: https://napster2210.github.io/ngx-spinner/
  •  
  •  
  • Login with token
    • Add token creation webapi
  • [HttpPost]public async Task<IActionResult> CreateToken([FromBody]LoginViewModel vm){if (ModelState.IsValid){var user = await userMgr.FindByNameAsync(vm.UserName);if (user != null){var result = await signinMgr.CheckPasswordSignInAsync(user, vm.Password, false);if (result.Succeeded){var Claimns = new[]{new Claim(JwtRegisteredClaimNames.Sub, user.Email),new Claim(JwtRegisteredClaimNames.Jti, new Guid().ToString()),new Claim(JwtRegisteredClaimNames.UniqueName, user.UserName)};var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(config["token:key"]));var cred = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);var token = new JwtSecurityToken(config["token:issuer"],config["token:audience"],Claimns,expires: DateTime.Now.AddMinutes(30),signingCredentials: cred);var results = new {token = new JwtSecurityTokenHandler().WriteToken(token),expire = token.ValidTo};return Created("", results);}}}return BadRequest();}

     


    • Add token authorize to api
    • Add token authentication at middleware - ConfigureService and Configure
      •  

    • Client Id token cache and forware at header in api call
      •  

  • 2 ways binding
  • Validation

 Parameterized component

 Param setting from Parent to Child and Child postback message to Parent

 

 

 

 

 

 

 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/1174492.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

基于深度学习的香蕉成熟度识别检测系统(YOLOv10+YOLO数据集+UI界面+Python项目源码+模型)

一、项目介绍 本文介绍了基于YOLOv10的香蕉成熟度检测系统&#xff0c;旨在通过计算机视觉技术自动识别和分类香蕉的成熟度。该系统能够准确区分六种不同的成熟度类别&#xff1a;新鲜成熟&#xff08;freshripe&#xff09;、新鲜未成熟&#xff08;freshunripe&#xff09;、…

基于深度学习的疲劳驾驶检测系统(YOLOv10+YOLO数据集+UI界面+Python项目+模型)

一、项目介绍 本项目旨在开发一个基于YOLOv10的疲劳检测系统&#xff0c;用于实时检测驾驶员的疲劳状态。系统通过分析驾驶员的面部表情&#xff0c;特别是眼睛和嘴巴的状态&#xff0c;来判断其是否处于疲劳状态。模型共分为四类&#xff1a;打哈欠&#xff08;Yawn&#xff0…

强烈安利!自考必看TOP8一键生成论文工具测评

强烈安利&#xff01;自考必看TOP8一键生成论文工具测评 2026年自考论文工具测评&#xff1a;为何需要一份权威榜单&#xff1f; 随着自考人数逐年增加&#xff0c;论文写作成为众多考生必须面对的难题。从选题构思到文献整理&#xff0c;再到格式规范和内容润色&#xff0c;每…

基于深度学习的生菜周期检测系统(YOLOv10+YOLO数据集+UI界面+Python+模型)

一、项目介绍 YOLOv10生菜生长周期检测系统 是一个基于YOLOv10&#xff08;You Only Look Once version 10&#xff09;目标检测算法的智能系统&#xff0c;专门用于检测和分类生菜在不同生长阶段的生长状态。该系统能够自动识别生菜的生长周期&#xff0c;并将其分类为五个不…

西门子200Smart加Smart 1000 IE水处理程序画面案例。 采用成熟、可靠、先进、...

西门子200Smart加Smart 1000 IE水处理程序画面案例。 采用成熟、可靠、先进、自动化程度高的反渗透精混床除盐水处理工艺&#xff0c;确保处理后的超纯水水质确保处理后出水电阻率达到18.2MΩ.cm, 高纯水制取设备关键设备及耗材采用国际主流先进可靠产品&#xff0c;采用PLC触摸…

震惊!这家浙江头部AI科技公司,竟然藏着这样的秘密!

震惊&#xff01;这家浙江头部AI科技公司&#xff0c;竟然藏着这样的秘密&#xff01;当前行业内对AI技术的认知多聚焦于技术迭代&#xff0c;却鲜少关注落地环节的“适配成本”问题。尤其在中小微企业中&#xff0c;这一痛点尤为突出。许多企业在推进AI转型时&#xff0c;常常…

计算机毕业设计 java 疫苗预约系统 基于 Java 的智能疫苗接种预约管理平台 Java 疫苗接种全流程管理系统

计算机毕业设计 java 疫苗预约系统 9&#xff08;配套有源码 程序 mysql 数据库 论文&#xff09;本套源码可以先看具体功能演示视频领取&#xff0c;文末有联 xi 可分享随着网络科技的飞速发展和人们健康意识的提升&#xff0c;疫苗预约需求日益增长&#xff0c;传统线下预约模…

PERFORMANCE TEST - WebPerf Test

PERFORMANCE TEST - WebPerf TestNo web browser Organize your test early on -could be base on user stories Small granularity so you know what is slowAdding Validatation Rule All have LEVEL to indicate im…

震惊!浙江这家头部AI公司光景泽创,究竟藏着啥秘密?

震惊&#xff01;浙江这家头部AI公司光景泽创&#xff0c;究竟藏着啥秘密&#xff1f;当多数AI企业还在卷技术参数时&#xff0c;浙江光景泽创科技公司&#xff08;以下简称“光景泽创”&#xff09;却用一组数据刺痛了行业神经&#xff1a;服务企业超500家&#xff0c;帮助广州…

震惊!浙江这家AI科技头部公司光景泽创,究竟有何过人之处?

跨境生意的“效率革命”&#xff1a;解码光景泽创的AI破局之道当前跨境电商行业正陷入一场“效率焦虑”——多语言素材人工翻译成本高、海外直播时区适配难、客户咨询响应慢导致流失率超30%&#xff0c;这些隐性痛点正在吞噬企业的利润空间。浙江光景泽创科技有限公司&#xff…

Dev Mentor - RabbitMq

Dev Mentor - RabbitMqBus is to be used to inform or broadcast the mutated state and command that need to be processed by multiple servicesScenario 1 ProductService received rest post message to persist…

PyTorch 自动微分:超越 `backward()` 的动态图深度探索

PyTorch 自动微分&#xff1a;超越 backward() 的动态图深度探索 引言&#xff1a;自动微分的范式之争 在深度学习的工程实践中&#xff0c;自动微分&#xff08;Automatic Differentiation, AD&#xff09;已成为模型训练的基石。与符号微分和数值微分不同&#xff0c;自动微分…

计算机毕业设计 java 疫情物资管理系统 Java 疫情物资智能管理与调配平台 基于 Spring Boot 的疫情物资申请捐赠系统

计算机毕业设计 java 疫情物资管理系统 v5rne9&#xff08;配套有源码 程序 mysql 数据库 论文&#xff09;本套源码可以先看具体功能演示视频领取&#xff0c;文末有联 xi 可分享在疫情防控常态化背景下&#xff0c;疫情物资的高效管理、精准调配与供需对接成为关键需求&#…

震惊!浙江这家AI科技公司,竟是光景泽创!

浙江光景泽创科技&#xff1a;AI 企服领域的创新引领者在当今数字化浪潮汹涌的时代&#xff0c;AI 技术在企业服务领域的应用正成为行业发展的关键驱动力。然而&#xff0c;企业在引入 AI 服务时&#xff0c;往往面临着诸多挑战。从行业实操反馈来看&#xff0c;许多企业在 AI …

Dev Mentor - Seq Serilog

Dev Mentor - Seq Serilog {"app": {"name": "order-service"},"elk": {"enabled": false,"url": "http://10.89.24.148:9200","indexFo…

基于深度学习的棉花分类检测系统(YOLOv8+YOLO数据集+UI界面+Python项目+模型)

一、项目介绍 摘要 本项目基于YOLOv8深度学习目标检测算法&#xff0c;开发了一套高效、精准的棉花品种智能分类检测系统。该系统能够自动识别并分类四种主要棉花品种&#xff1a;亚洲棉&#xff08;G. arboreum&#xff09;、海岛棉&#xff08;G. barbadense&#xff09;、…

基于深度学习的手势识别检测系统(YOLOv8+YOLO数据集+UI界面+Python项目+模型)

一、项目介绍 摘要 本项目基于先进的YOLOv8深度学习算法&#xff0c;开发了一套高效精准的实时手势识别检测系统。系统能够准确识别10种常见手势&#xff0c;包括字母手势&#xff08;A、D、I、L、V、W、Y&#xff09;、数字手势&#xff08;5、7&#xff09;以及特殊手势&am…

Dev Mentor - Distributed tracing

Dev Mentor - Distributed tracingOpenTrace take a tracer instance (e.g. Jaeger) to post the metrics via UDP to the remote Jaeger instance for display OpenTrace then can be acquired in DI manner and get …

基于深度学习的火焰烟雾检测系统(YOLOv10+YOLO数据集+UI界面+Python项目+模型)

一、项目介绍 项目背景 火焰与烟雾的检测在很多领域中都至关重要&#xff0c;特别是在火灾监控、工业安全、环境保护等领域。准确、实时地识别火焰和烟雾的存在&#xff0c;不仅可以有效减少灾害发生的损失&#xff0c;还能够为相关部门提供及时的预警信息。因此&#xff0c;…

VIRTUALIZATION - Dev Mentor - Kubernates (Continue)

VIRTUALIZATION - Dev Mentor - Kubernates (Continue) kubectl apply -f /home/Asdf1234/pod.ymlkubectl get podskubectl port-forward nanoservice-pod 5000:5000kubectl describe pod nanoservice-pod kubectl de…