我正在尝试在Angular应用程序中为http服务实现缓存.
我的代码在服务countriesService
public get(): Observable<any> {
return this.http.get(`/countries`, {})
.map(res => res.json())
.publishReplay(1)
.refCount();
}
Run Code Online (Sandbox Code Playgroud)
在组件CountriesComponent中,我有
ngOnInit() {
this.countriesService.get()
.subscribe(res => {
this.countries = res.countries;
});
}
Run Code Online (Sandbox Code Playgroud)
我在路由配置中加载组件
const appRoutes: Routes = [
{ path: 'countries', component: CountriesComponent },
{ path: 'cities', component: CitiesComponent },
];
Run Code Online (Sandbox Code Playgroud)
每当我从城市返回国家时,我都会看到=>/countries的请求.它不应该激活请求,因为它应该被缓存(这是它在角度1.x中使用promises的工作方式),而不是角度4和rxJs.
我正在使用角形材料和反应形式。我想要显示错误消息时,仅显示一条消息,如果解决一个错误,则显示另一条消息。
现在如何:
HTML:
<mat-form-field class="example-full-width">
<input matInput
placeholder="Username"
name="username"
[formControlName]="'username'">
<mat-error *ngIf="form.controls['username'].errors && form.controls['username'].touched">
<div *ngIf="form.controls['username'].errors.required">
Username is <strong>required</strong>
</div>
<div *ngIf="form.controls['username'].errors.minlength">
Required length: {{form.controls['username'].errors.minlength['requiredLength']}}
Actual length:{{form.controls['username'].errors.minlength['actualLength']}}
</div>
<div *ngIf="form.controls['username'].errors.pattern">
Only a-zA-Z0-9
</div>
</mat-error>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
也许我应该使用其他的东西?你怎么看?
简单的问题:
以下有效载荷:
{
"aud": ["aud1", "aud2"]
}
Run Code Online (Sandbox Code Playgroud)
相当于:?
{
"AUD": ["aud1", "aud2"]
}
Run Code Online (Sandbox Code Playgroud) 我有一个关于heroku架构的问题.我正在创建运行为微服务的小应用程序(不是很多 - 大约4-6个微服务).关键是,我希望这个应用程序全天候可用,所以免费的dyno小时对我来说是不够的.
我看到如果我要扩展hobby计划,我会得到heroku所说的东西10 Process Types.我的问题来了:
我可以在每个进程(web)上运行另一个微服务,或者heroku只能为每个dyno安装一个Web进程,并且给出10 process types用于扩展我的应用程序的能力?换句话说,如果我需要6个24/7运行的微服务我应该买6个爱好dynos吗?
所以我的代码编译时没有错误,但是在使用时出现错误......
我的表单组件:
export class OrderHeaderComponent implements OnInit {
orderForm: FormGroup;
orderLines: FormArray;
ngOnInit() {
// build the form model
this.orderLines = this.fb.array([])
this.orderForm = this.fb.group({
orderHeadForm: this.fb.group({ // create nested formgroup to pass to child
selectTypeahead: ['',
Validators.required],
ohReference: ['',
Validators.required],
}),
orderLines: this.orderLines,
})
}
someFunction(){
this.orderLines.push(this.fb.group({
['newInputName']: ['',
Validators.required],
}));
}
}
Run Code Online (Sandbox Code Playgroud)
现在这是一个父组件,它将表单传递给各个子组件(这可以减去我当前正在处理的 formArray 部分)。每个孩子看起来像这样:parent_template:
<form [formGroup]="orderForm" (ngSubmit)="orderFormSubmit()">
<childTemplate [orderHeadForm]="orderForm.controls.orderHeadForm">
</childTemplatet>
</form>
Run Code Online (Sandbox Code Playgroud)
子模板:
<div class="form-group" [formGroup]="orderHeadForm">
<label for="oh-custaccount">Customer Account #</label>
<input class="form-control" type="text"
formControlName="selectTypeahead"
(focusout)=lookupCustomerAccountReactive() />
<p *ngIf="orderHeadForm.controls.selectTypeahead.errors?.required" …Run Code Online (Sandbox Code Playgroud) 我想用输入测试简单的角度组件。
所以底部的一个例子几乎没有为测试做准备,并且在一个组件中应该发生test功能模糊,它显示日志,但我在控制台中没有日志。我尝试了两种情况:获取 div 原生元素并单击它并使用blur()函数输入原生元素。在 angular 应用程序中成功发生模糊,但在测试中不起作用。我该如何解决?
@Component({
template: '<div><input [(ngModel)]="str" (blur)="testFunc($event)" /></div>'
})
class TestHostComponent {
it: string = '';
testFunc = () => {
console.log('blur!!!');
}
}
describe('blur test', () => {
let component: TestHostComponent;
let fixture: ComponentFixture<TestHostComponent>;
let de: DebugElement;
let inputEl: DebugElement;
beforeEach(() => { /* component configuration, imports... */ }
beforeEach(() => {
fixture = TestBed.createComponent(TestHostComponent);
component = fixture.componentInstance;
de = fixture.debugElement;
inputEl = fixture.debugElement.query(By.css('input'));
fixture.detectChanges();
})
it('test', async(() => {
const …Run Code Online (Sandbox Code Playgroud) 一个非常基本的设置,组件:
export class LayerComponent {
public content: string;
constructor(content: string) {
this.content = content;
}
}
Run Code Online (Sandbox Code Playgroud)
及其模板:
<p>{{content}}</p>
Run Code Online (Sandbox Code Playgroud)
从另一个组件,我想(静态)实例化所描述的传入内容参数的组件(无需绑定它)。我采用了以下不起作用的方法:
<ipe-artboard-layer content="Joep"></ipe-artboard-layer>
<ipe-artboard-layer content="Floris"></ipe-artboard-layer>
<ipe-artboard-layer content="Casper"></ipe-artboard-layer>
Run Code Online (Sandbox Code Playgroud)
这种方法是否可行,建议?我宁愿不去进行真正的绑定,因为它只是用它的某些属性的一次性初始值来实例化组件。
在我的Angular应用程序中,我的菜单组件html代码在页面加载时会短暂显示.即使我使用display none css隐藏菜单html根元素,当页面开始加载时仍会显示html.我已经阅读了很多关于ng-cloak(https://docs.angularjs.org/api/ng/directive/ngCloak)的内容,但似乎Angular 4没有ngCloak.
所以我不知道如何防止这种不愉快的影响.
Angular 4是否有ng-cloak的等效指令?如何正确显示页面而不显示加载时没有样式的HTML?
我正在日复一日地学习角度,但我遇到了问题.我在一个组件中有3个值,我需要将它们传递给另一个组件.我对observable和subscription有基本的了解,但我用1参数完成了它.现在我想播放3个值
这是我的购物车代码.
additem(itemText){
this.cart.push(itemText);
this.itemscount = this.cart.length;
this._data.changeCart(this.cart);
}
Run Code Online (Sandbox Code Playgroud)
当我点击产品时,这个函数会调用它并将cart数组发送到observable,并在那里广播购物车数组
export class DataService {
private cart = new BehaviorSubject<any>([]);
cast = this.cart.asObservable();
constructor() { }
changeCart(item_param) {
this.cart.next(item_param);
//console.log(this.cart);
}
}
Run Code Online (Sandbox Code Playgroud)
现在我需要将3个值传递给observable,我很困惑如何做到这一点因为我已经读过我们只能将一个值传递给observable.我有一个想法将所有值包装在一个数组中并传递该数组,但我搜索了这个但却找不到如何在单个数组中以角度存储多个值.
任何帮助将非常感谢.谢谢
错误:
An exception has been thrown during the rendering of a template
"You have requested a non-existent service "C". Did you mean one of
these: "Symfony\Bundle\FrameworkBundle\Controller\RedirectController",
"Symfony\Bundle\FrameworkBundle\Controller\TemplateController
Run Code Online (Sandbox Code Playgroud)
如何在symfony 4中打开FOSJsRoutingBundle?
bundles.php:
FOS\JsRoutingBundle\FOSJsRoutingBundle::class => ['all' => true]
Run Code Online (Sandbox Code Playgroud)
routes.yaml:
fos_js_routing:
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"
Run Code Online (Sandbox Code Playgroud)
layout.html.twig:
<script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
<script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>
Run Code Online (Sandbox Code Playgroud) 让我们想象一下这样的情况:
我们有node.js 应用程序,它在服务器端渲染视图并将html 发送到浏览器。在生成的 html 中,我们几乎没有静态资源(如图像、样式表等)。
以下是我看到的优点和缺点:
我非常确定从 S3 提供内容比从 Lambda 提供内容要快得多(没有需要执行的脚本)...
...直到我执行了一些测试(文件大小 ~44kB)平均 10 个请求:
正如您所看到的,通过 API GW 从 Lambda 提供内容与从 S3 提供内容没有区别。唯一显着的区别是直接链接到 s3 和之前的两次测试之间。
拉姆达 1 : S3 1
在这里 Lambda 绝对获胜。
首先,我们对 1 000 000 个请求进行免费分类,其次是定价:
(每 100 万个请求 0.20 美元 + 每 100 毫秒 0.000000208 美元)
因此,在定价方面,Lambda 获胜。
我的观察表明,Lambda 甚至是提供静态内容的更好方式(速度与 …
我想在我的全局异常处理程序中捕获HTTP错误.
异常处理程序适用于大多数异常,但不会捕获可观察的异常.我想要捕获的异常是HTTP异常.
这就是我尝试将HTTP可观察错误发送到异常处理程序的方法.
import { Injectable } from '@angular/core';
import { Request, XHRBackend, RequestOptions, Http, Response, RequestOptionsArgs } from '@angular/http';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';
import { HttpException } from '../exceptions/http-exception';
import {Observable} from 'rxjs/Observable';
@Injectable()
export class HttpErrorService extends Http {
constructor(backend: XHRBackend, defaultOptions: RequestOptions) {
super(backend, defaultOptions);
}
request(url: string | Request, options?: RequestOptionsArgs) {
return super.request(url, options).catch((error: Response) => {
// Bypass lint.
fail();
function fail() {
// Here I want to throw the exception to send it …Run Code Online (Sandbox Code Playgroud) List<Map<String, String>> personList = new ArrayList<HashMap<String, String>> ();
String tempcnic = SBox.getText().toString();
HashMap<String,String> temp = new HashMap<>();
for (int i = 0; i < personlistcopy.size(); i++) {
temp = personlistcopy.get(i);
if (temp.get(TAG_CNIC) == tempcnic) {
Toast.makeText(History.this, temp.get(TAG_CNIC), Toast.LENGTH_SHORT).show();
personList2.add(temp);
}
temp = null;
}
Run Code Online (Sandbox Code Playgroud)
我有一个ArrayList包含HashMaps,
HashMap包含 4 个具有相应值的键。
请帮我做“搜索并找到给定 cnic 中的所有HashMapsArrayList并将它们添加到新的ArrayList。新的ArrayList将拥有该 cnic 的所有记录。”