Angular.x读取本地静态json文件(引入json文件使用)

由于项目下拉加载数据过多(城市、行业),所以将数据封装成json数据放存放angular中静态文件的assets目录下,

  1. 将json文件放入到assets文件下;
  2. 在这里插入图片描述
  3. 需要引入json页面的ts页面中,导入@angular/common/http,并再构造函数中声明便于使用(本人参考网上都是使用@angular/http自己尝试发现是存在横杆,估计是更新后失效了)
    *import {HttpClient} from ‘@angular/common/http’;
    构造中声明:
    在这里插入图片描述
    4.如图,填写json文件路径,如下调取即可获取json数据;
    在这里插入图片描述
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
angular.jsonAngular CLI的配置文件,它用于配置Angular项目的各种构建选项。该文件包含了项目的各种配置信息,例如构建选项、构建目标、环境变量等等。下面是一个angular.json文件的示例: ```json { "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "newProjectRoot": "projects", "projects": { "my-app": { "root": "", "sourceRoot": "src", "projectType": "application", "prefix": "app", "schematics": {}, "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "outputPath": "dist/my-app", "index": "src/index.html", "main": "src/main.ts", "polyfills": "src/polyfills.ts", "tsConfig": "src/tsconfig.app.json", "assets": [ "src/favicon.ico", "src/assets" ], "styles": [ "src/styles.css" ], "scripts": [] }, "configurations": { "production": { "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.prod.ts" } ], "optimization": true, "outputHashing": "all", "sourceMap": false, "extractCss": true, "namedChunks": false, "aot": true, "extractLicenses": true, "vendorChunk": false, "buildOptimizer": true } } }, "serve": { "builder": "@angular-devkit/build-angular:dev-server", "options": { "browserTarget": "my-app:build" }, "configurations": { "production": { "browserTarget": "my-app:build:production" } } }, "extract-i18n": { "builder": "@angular-devkit/build-angular:extract-i18n", "options": { "browserTarget": "my-app:build" } }, "test": { "builder": "@angular-devkit/build-angular:karma", "options": { "main": "src/test.ts", "polyfills": "src/polyfills.ts", "tsConfig": "src/tsconfig.spec.json", "karmaConfig": "src/karma.conf.js", "styles": [ "src/styles.css" ], "scripts": [], "assets": [ "src/favicon.ico", "src/assets" ] } } } } }, "defaultProject": "my-app" } ``` 在这个示例中,我们可以看到该文件定义了一个名为“my-app”的项目,其中包含了“build”、“serve”、“extract-i18n”和“test”四个构建目标。每个构建目标都有自己的构建选项和配置信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值