我正在使用Angular Maps构建地图应用程序,并希望将JSON文件导入为定义位置的标记列表.我希望在app.component.ts中使用这个JSON文件作为marker []数组.而不是在TypeScript文件中定义硬编码的标记数组.
导入此JSON文件以在我的项目中使用的最佳过程是什么?任何方向都非常感谢!
你能告诉我angular2和angular4之间的区别吗?我们知道angular1和angular2之间存在巨大的变化.是否为angular4再次重复.
我试图使用Angular 2中的Http类获取一个json文件.我按照Angular 2主页上的示例进行操作:https://angular.io/docs/js/latest/api/http/Http-class.html.但是,我收到以下错误消息.我使用的是Angular 2.0.0-alpha.37,traceur 0.0.91,systemjs 0.16.11,es6-module-loader 0.16.6和typescript 1.6.2.关于这里可能有什么问题的任何想法?
app.ts
///<reference path="typings/angular2/angular2.d.ts"/>
///<reference path="typings/angular2/http.d.ts"/>
import {Component, View, bootstrap} from 'angular2/angular2';
import {Http, HTTP_BINDINGS} from 'angular2/http';
@Component({
selector: 'myApp',
viewBindings: [HTTP_BINDINGS]
})
@View({
templateUrl: 'myapp.html'
})
class MyComponent {
data: Object;
constructor(http: Http) {
http.get('data.json').toRx().map(res => res.json()).subscribe(data => this.data = data);
}
}
bootstrap(MyComponent);
Run Code Online (Sandbox Code Playgroud)
的index.html
<!DOCTYPE html>
<html>
<head>
<script src="../node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="../node_modules/angular2/bundles/http.dev.js"></script>
<script src="../node_modules/traceur/bin/traceur-runtime.js"></script>
<script src="../node_modules/es6-module-loader/dist/es6-module-loader.js"></script>
<script src="../node_modules/systemjs/dist/system.src.js"></script>
</head>
<body>
<myApp></myApp>
<script>
System.import('app');
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
结果 …
我试图在typescript类中导入json文件
import * as nationalities from './mock/nationalities.json';
Run Code Online (Sandbox Code Playgroud)
它给了我一个错误
找不到模块'./mock/nationalities.json'.
为了解决这个问题,我添加了这个
declare module '*.json' {
const value: any;
export default value;
}
Run Code Online (Sandbox Code Playgroud)
但它没有解决我的问题,也给了我另一个错误异常
增强中的模块名称无效,无法找到模块'*.json'.
我的打字稿版本
2.9.2
我有一个用angular4编写的应用,正在生产环境和沙箱上运行,
我创建一个映像,然后在kubernetes上进行部署
我有一些与沙箱和生产环境不同的环境变量,目前我建立了两个不同的映像,一个用于沙箱,另一个用于生产:
下的环境src/envirnments
:
环境产品
export const environment = {
production: true,
server_url: 'https://api.example.com/app/',
};
Run Code Online (Sandbox Code Playgroud)
environment.sandbox.ts
export const environment = {
production: false,
server_url: 'https://api-sandbox.example.com/app/',
};
Run Code Online (Sandbox Code Playgroud)
建筑形象:
生产:ng build --prod
沙箱:
ng build--prod --env=sandbox
现在,我该如何使用外部环境变量呢?像这样的东西applicatoion.getEnvirnment('server_url')
,我不需要为每个环境创建图像吗?
这是我的deployment.yaml
:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: angular-web-app
namespace: production
spec:
replicas: 1
revisionHistoryLimit: 1
strategy:
type: RollingUpdate
template:
metadata:
labels:
app: angular-web-app
spec:
containers:
- name: angular-web-app
image: us.gcr.io/my-com/angular-web-app:06.01.2018
ports:
- containerPort: 80
env:
- …
Run Code Online (Sandbox Code Playgroud) angular ×5
typescript ×3
angular4 ×1
angular5 ×1
google-maps ×1
ionic2 ×1
ionic3 ×1
json ×1
kubernetes ×1
maps ×1