迁移到TS 2.2.2后,这个错误开始弹出,所以我假设这是问题......代码没有停止工作,但现在我收到了这个错误,我尝试了一些事情,比如返回一个空的observable捕获重新抛出的异常并返回一个对象,似乎没有任何工作.为什么现在发生这种情况?它不应该理解我重新抛出异常而不期待回归吗?我误读了这个错误吗?
这是完整的错误描述:
这是完整的代码:
return request
.map((res: Response) => res.json())
.catch((error: any) => {
// todo: log?
if (error.status == 500) {
this.alertService.showError(error.statusText);
} else if (error.status == 588) {
this.alertService.showAlert(error.statusText);
}
Observable.throw(error.statusText);
});
Run Code Online (Sandbox Code Playgroud)
我尝试返回Observable,但我的包装器方法需要返回类型T,这是我的反序列化请求(map(...))的返回.如果我确实返回,throw这是我得到的错误:
[ts]类型'Observable'不能赋值为'T'
我正在使用:
- Angular4
- 打字稿2.2.2
你能告诉我angular2和angular4之间的区别吗?我们知道angular1和angular2之间存在巨大的变化.是否为angular4再次重复.
您好SO社区和Angularians!
因此,我正在Angular 2中开发一个巨大的平台.我意识到Angular 2的许多外部库和依赖项正在迁移到新的Angular 4.很明显,给了我许多错误.
我可以分叉这些库并使用分叉版本并订阅主库开发,或者我可以升级到Angular 4我的项目.
要回答的问题是为了确定我是否值得迁移:
我发现了一些改进以确保与遗留的兼容性,如下所示:https://github.com/angular/angular/commit/e99d721
我是否必须通过我的整个应用程序并开始修复?
我的意思是,主要功能是否以这种方式重新设计,我将不得不审查其中的许多功能?
或者,是否有许多构建/核心不兼容性,这将使我几天占用修复编译错误/警告而不是开发?
我不是要求有人为我做研究,我问人们可能已经完成了这个过程,或者只是熟悉两个版本,以便给我一些经验提示,澄清等.
目前,我在这里做研究:
UPDATE
我刚刚迁移到Angular 4.@PierreDuc在他的回答中提供的链接是一个非常好的工具,可以在迁移过程中获得合适的指导.
我建议:
我还建议您提交当前项目,在dev存储库中创建一个新分支,然后继续在该分支中进行迁移.
一个问题,我遇到:
Input,Output并ContentChild会从错误的道路进口.
我的情况:
import { Component, OnInit, OnDestro } from '@angular/core';
import { Input, ContentChild } from "@angular/core/src/metadata/directives";
Run Code Online (Sandbox Code Playgroud)
解:
import { Component, OnInit, OnDestroy, Input, ContentChild } from '@angular/core';
Run Code Online (Sandbox Code Playgroud) 我尝试在Internet Explorer 11中运行由angular-cli 1.0.0构建的我的处女Angular 4应用程序,但是我没有成功,我收到以下错误:
Error: The "apply" property of an undefined or null reference can not be retrieved.
Run Code Online (Sandbox Code Playgroud)
我没有安装额外的库,它只是一个新生成的项目.在谷歌浏览器中它完美运行.我的package.json:
{
"name": "angi4testie",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@angular/router": "^4.0.0",
"core-js": "^2.4.1",
"rxjs": "^5.1.0",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/cli": "1.0.0",
"@angular/compiler-cli": "^4.0.0", …Run Code Online (Sandbox Code Playgroud) 目的:我想在从一个页面点击到另一个页面时添加一个很好的过渡效果
我在网上尝试了很多解决方案,包括:
一个共同点是它们都有类似position: absolute或position: fixed添加的样式,这打破了我现有的应用程序布局.
在使用角1我记得,有没有必要添加position: absolute到<div ui-view><div>
Angular 2还是4?
我刚刚用CLI创建了一个新的Angular 4项目: ng new test
版本:
@angular/cli: 1.0.0
node: 6.10.0
os: win32 x64
@angular/common: 4.0.1
@angular/compiler: 4.0.1
@angular/core: 4.0.1
@angular/forms: 4.0.1
@angular/http: 4.0.1
@angular/platform-browser: 4.0.1
@angular/platform-browser-dynamic: 4.0.1
@angular/router: 4.0.1
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.1
Run Code Online (Sandbox Code Playgroud)
但是,由于我未使用的类FooBar仍在main.*.js文件中,因此树抖动无法正常工作.
我的示例组件TS文件(FooBar不应该在输出中):
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
}
export class FooBar {
foo = "hello";
}
Run Code Online (Sandbox Code Playgroud)
我试图使用汇总(如文档中所述),但这不起作用......
有没有一种简单的方法来启用树木摇晃?(我希望在通过CLI创建项目时默认启用它).
更新:我正在使用ng build --prod它仍然没有被震动..
我有一个Directive可以放置元素来检查相关元素的当前滚动位置.
看起来像这样:
@Directive({
selector: '[my-scroll-animation]'
})
Run Code Online (Sandbox Code Playgroud)
每当位置满足某个阈值时,我希望元素使用动画显示在屏幕上.我知道,Component我可以附加animations属性以及属性中的一些设置host来激活动画.
我想要这样的东西:
import { myScrollAnimation } from './animations';
@Directive({
selector: '[my-scroll-animation]'
animations: [myScrollAnimation] // <- not possible?
})
Run Code Online (Sandbox Code Playgroud)
如何在指令中实现这一目标?
使用:Angular 4.0.0-rc.4
我收到这个警告:
The <template> element is deprecated. Use <ng-template> instead ("
[attr.tabIndex]="-1"
[ngClass]="{'k-item': true}">
[WARNING ->]<template *ngIf="template"
[templateContext]="{
Run Code Online (Sandbox Code Playgroud)
当使用角度4时,是否需要处理发布版本?
谢谢
在我的组件中有一个像这样的模板
template: '<input type="text" value="{{formattedValue}}">',
当输入某些错误输入时,内部的formattedValue属性不会更改,但我希望UI随后更新以显示最后一个正确的值.
例如,如果组件this.formattedValue为1,000并且用户更新输入以使文本1,000xI然后希望输入再次为1,000.目前这不会发生.当然我可以在函数中使用Dom api更新DOM,但我更喜欢使用模板.
在Codelyzer测试文件中,我看到了样式内联模板中使用的SCSS.是否可以使用Angular CLI启用它?
我的SCSS设置在使用时工作,styleUrls但不适用于直接styles组件装饰器属性.
更新:
我正在使用Angular CLI 1.0.0和Angular 4.0.1
这是WebStorm IDE中显示的错误
angular4 ×10
angular ×9
angular-cli ×2
typescript ×2
animation ×1
javascript ×1
migration ×1
ng-template ×1
sass ×1
transition ×1
tree-shaking ×1