本文将介绍如何解决TypeError:environment.teardown不是函数?的详细情况,特别是关于typeerrorisnotafunction的相关信息。我们将通过案例分析、数据研究等多
本文将介绍如何解决TypeError:environment.teardown不是函数?的详细情况,特别是关于typeerror is not a function的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于Angular 12:如何为每种语言使用单独的 environment.ts 文件(例如 environment.en.ts、environment.de.ts)?、Angular 2 HTTP请求:TypeError:backend.createConnection不是函数、angular – ng-bootstrap typeahead TypeError:Object(…)不是函数、angular – 数据表问题 – ERROR TypeError:val.slice不是函数的知识。
本文目录一览:- 如何解决TypeError:environment.teardown不是函数?(typeerror is not a function)
- Angular 12:如何为每种语言使用单独的 environment.ts 文件(例如 environment.en.ts、environment.de.ts)?
- Angular 2 HTTP请求:TypeError:backend.createConnection不是函数
- angular – ng-bootstrap typeahead TypeError:Object(…)不是函数
- angular – 数据表问题 – ERROR TypeError:val.slice不是函数
如何解决TypeError:environment.teardown不是函数?(typeerror is not a function)
我无法测试使用create-react-app创建的应用程序,所有指南均表示该测试默认情况下有效,但是当我尝试“纱线测试”时,它要求安装“ jest-
cli”,并且安装后出现错误“ TypeError:environment”。拆卸不是功能”。
答案1
小编典典您不需要自己安装jest-cli,它应该是开箱即用的。
尝试以下方法:
- 删除package-lock.json,yarn.lock和node_modules
- 从package.json中的依赖项中删除笑话
- 然后执行
npm install
或yarn install
。
Angular 12:如何为每种语言使用单独的 environment.ts 文件(例如 environment.en.ts、environment.de.ts)?
如何解决Angular 12:如何为每种语言使用单独的 environment.ts 文件(例如 environment.en.ts、environment.de.ts)??
我一直在开发一款多语言 Angular 应用,并将其部署到 Firebase 托管。
https://myAppDomain.de/de 显示德文版。
https://myAppDomain.de/en 显示英文版。
这在大多数情况下都可以正常工作,除了我将一些特定于语言环境的变量放入 environment.ts 中:
numberFormatLocale: ''de'',dateFormatLocale: ''de-DE'',timePickerLocale: ''de-DE'',momentLocale: ''de'',...
我希望这些值根据应用程序的语言而改变。
因此,我创建了单独的 environment.ts 文件:
environment.ts
作为英文开发环境文件,environment.prod.ts
作为英文 prod 环境文件,environment.de.ts
作为德语开发环境文件,environment.prod.de.ts
作为德国生产环境文件,
我试图在构建过程中替换它们,所以我这样配置 angular.json
:
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser","options": {
"i18nMissingTranslation": "error","localize": true,"outputPath": "dist/myAppDomain","index": "src/index.html","main": "src/main.ts","polyfills": "src/polyfills.ts","tsConfig": "tsconfig.app.json","assets": [
"src/favicon.ico","src/assets","src/manifest.webmanifest",{
"glob": "**/*","input": "node_modules/ngx-auth-firebaseui/assets/","output": "./assets/"
}
],...
},"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts","with": "src/environments/environment.prod.ts"
},{
"replace": "src/environments/environment.de.ts","with": "src/environments/environment.prod.de.ts"
}
],...
},"de": {
"localize": [
"de"
],"baseHref": "/de/","fileReplacements": [
{
"replace": "src/environments/environment.prod.ts","with": "src/environments/environment.prod.de.ts"
},{
"replace": "src/environments/environment.ts","with": "src/environments/environment.de.ts"
}
]
},"en": {
"localize": [
"en"
],"baseHref": "/en/"
}
},},
但是,它不起作用。我总是得到英文环境.ts,不管我加载哪个语言版本。
我该如何正确配置?或者,有什么更好的方法可以实现相同的目标?
2021-07-31 更新:
这是我的package.json
的摘录:
"scripts": {
"ng": "ng","start": "ng serve --configuration=en --port 4200 && ng serve --configuration=de --port 4201","start:en": "ng serve --configuration=en --port 4200","start:de": "ng serve --configuration=de --port 4201","build": "ng build","build:prod": "ng build --configuration=production","test": "ng test","lint": "ng lint","e2e": "ng e2e"
},
我还从我的 angular.json
中添加了一些更多信息。
解决方法
我决定走另一条路。我没有使用大量单独的环境文件(添加的语言越多越乏味),而是回到只有两个环境文件:一个用于开发,一个用于生产。
我创建了一个 locale.ts 类,它包含一个用于每个变量的函数,我曾经在 environment.ts 中使用过,如下所示:
private static numberFormatLocaleCache: string;
/**
* Number format locale
*/
static numberFormatLocale(): string {
if (!this.numberFormatLocaleCache) {
const currentLang = Locale.getCurrentLang();
switch (currentLang) {
case ''de'':
this.numberFormatLocaleCache = ''de'';
break;
default:
this.numberFormatLocaleCache = ''en'';
}
}
return this.numberFormatLocaleCache;
}
函数 getCurrentLang()
从当前路径中提取当前语言。对于https://myAppDomain.de/de,它返回''de''
;对于 https://myAppDomain.de/en,它返回 ''en''
。这是它的实现:
/**
* Delivers the current lang.
* @return language,e.g. ''en''
*/
static getCurrentLang(): string | undefined {
const path = window.location.pathname.replace(window.location.href,'''');
const parts = path.split(''/'');
if (parts.length < 2)
// The path does not contain a language code
return undefined;
const currentLang = return parts[1];
return currentLang;
}
注意:我首先尝试使用 Angular 模块来确定当前路径,例如this.router.url
来自 import { Router } from ''@angular/router'';
。
但是,如果调用组件不是当前的 <router-outlet>
,则这些都不能正常工作。例如,如果 Locale 类不是搜索组件的一部分,我会得到 https://myAppDomain.de/de/search 而不是 https://myAppDomain.de/de。
Angular 2 HTTP请求:TypeError:backend.createConnection不是函数
angular2.dev.js:23941 Error: Uncaught (in promise): EXCEPTION: Error during instantiation of AlbumListComponent!.
ORIGINAL EXCEPTION: TypeError: backend.createConnection is not a function
为了简化我将HTTP功能分解为最简单的删除服务,直接访问HTTP服务和Observable:
import {Component} from 'angular2/core'; import {Album} from './album'; import {AppState} from './appstate'; import {Observable} from 'rxjs/Observable'; import {Http} from 'angular2/http'; @Component({ selector: 'album-list',templateUrl: 'Views/albumList.html',providers: [AlbumService,Http,Response] }) export class AlbumListComponent { albums: Array<Album> = []; title: string = "Album Listing"; errorMessage: string; constructor(public state: AppState,public albumService: AlbumService,public http: Http) { console.log('AlbumList Constructor' + this.title); state.activeTab = "albums"; debugger; http.get(state.urls.albums) .map(res => { debugger; return res.json() }) //.catch(error => { // debugger; // console.error(error); // return Observable.throw(error.json().error || 'Server error'); //}) .subscribe(albums => this.albums = albums) //this.getAlbums(); // service removed to simplify } }
Bootstrap代码(和http.dev.js包含在脚本列表中):
import {bootstrap} from 'angular2/platform/browser'; import {Albumviewer} from './albumviewer.component'; import {ROUTER_PROVIDERS} from 'angular2/router'; import {HTTP_PROVIDERS} from 'angular2/http'; import {AppState} from './appstate' import 'rxjs/Rx'; bootstrap(Albumviewer,[ ROUTER_PROVIDERS,HTTP_PROVIDERS,]);
我要么得到描述的错误,要么得到关于缺少提供者的错误(比如ConnectionBackend).
如果我删除Http访问代码,应用程序运行正常.随着代码在那里炸弹.我不知道在这里看什么 – 因为错误消息明确指的是HTTP服务使用的子组件.
解决方法
在Angular2中,最后将HttpModule添加到@NgModule()的导入中也是如此
原版的
您不显示您的引导程序(…),但它可能不包含HTTP_PROVIDERS
bootstrap(AppComponent,[HTTP_PROVIDERS]);
HTTP_PROVIDERS包含Http及其所有依赖项.如果将HTTP_PROVIDERS添加到bootstrap(),则无需将Http添加到组件上的提供程序,因为这样可以使全局可用.
如果你想注入它,你仍然需要导入它.
angular – ng-bootstrap typeahead TypeError:Object(…)不是函数
但我不断收到以下错误:
ERROR TypeError: Object(...) is not a function at new NgbTypeahead (typeahead.js:52) at createClass (core.js:12449) at createDirectiveInstance (core.js:12284) at createViewNodes (core.js:13742) at callViewAction (core.js:14176) at execComponentViewsAction (core.js:14085) at createViewNodes (core.js:13770) at callViewAction (core.js:14176) at execComponentViewsAction (core.js:14085) at createViewNodes (core.js:13770)
并且:
ERROR TypeError: Cannot read property 'instance' of undefined at nodeValue (core.js:11753) at Object.eval [as handleEvent] (NgbdTypeaheadBasic.html:9) at handleEvent (core.js:13547) at callWithDebugContext (core.js:15056) at Object.debugHandleEvent [as handleEvent] (core.js:14643) at dispatchEvent (core.js:9962) at eval (core.js:10587) at HTMLDocument.eval (platform-browser.js:2628) at ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:4740)
我从网站link复制了Simple Typeahead代码.
我的package.json文件:
{
“名称”:“测试型提前”,
“版本”:“0.0.0”,
“执照”:“麻省理工学院”,
“脚本”:{
“ng”:“ng”,
“开始”:“ng serve”,
“build”:“ng build –prod”,
“测试”:“ng测试”,
“lint”:“ng lint”,
“e2e”:“ng e2e”
},
“私人”:是的,
“依赖”:{
“@ angular / animations”:“^ 5.2.0”,
“@ angular / common”:“^ 5.2.0”,
“@ angular / compiler”:“^ 5.2.0”,
“@ angular / core”:“^ 5.2.0”,
“@ angular / forms”:“^ 5.2.0”,
“@ angular / http”:“^ 5.2.0”,
“@ angular / platform-browser”:“^ 5.2.0”,
“@ angular / platform-browser-dynamic”:“^ 5.2.0”,
“@ angular / router”:“^ 5.2.0”,
“@ ng-bootstrap / ng-bootstrap”:“^ 2.0.0-alpha.0”,
“bootstrap”:“^ 4.1.0”,
“core-js”:“^ 2.4.1”,
“rxjs”:“^ 5.5.6”,
“zone.js”:“^ 0.8.19”
},
“devDependencies”:{
“@ angular / cli”:“~1.7.3”,
“@ angular / compiler-cli”:“^ 5.2.0”,
“@ angular / language-service”:“^ 5.2.0”,
“@ types / jasmine”:“~2.8.3”,
“@ types / jasminewd2”:“~2.0.2”,
“@ types / node”:“~6.0.60”,
“codelyzer”:“^ 4.0.1”,
“茉莉核心”:“~2.8.0”,
“jasmine-spec-reporter”:“~4.2.1”,
“业力”:“~2.0.0”,
“karma-chrome-launcher”:“~2.2.0”,
“karma-coverage-istanbul-reporter”:“^ 1.2.1”,
“karma-jasmine”:“~1.1.0”,
“karma-jasmine-html-reporter”:“^ 0.2.2”,
“量角器”:“~5.1.2”,
“ts-node”:“~4.1.0”,
“tslint”:“~5.9.1”,
“打字稿”:“~2.5.3”
}
}
到目前为止我尝试了什么:
>用npm重新安装node_modules – 没有帮助
>使用角度CLI开始了一个全新的项目并在那里试用了代码 – 没有帮助.
任何帮助是极大的赞赏!
解决方法
所以package.json文件:
`dependencies .... "@ng-bootstrap/ng-bootstrap": "^1.1.1",.... dependencies`
感谢JB Nizet和Niladri的快速解答
编辑:另外,正如@Niladri在评论中所说,你需要为你想要使用的模块使用forRoot().这是针对Angular 5的official documentation of version 1.1,这里说的是,但更新版本的角度曲线的新文档并未说明,因为它已被更改.所以记住这一点!
angular – 数据表问题 – ERROR TypeError:val.slice不是函数
val.slice is not a function
dataTable配置
$.p-dataTable #dt [value]="customers" [(selection)]="chkBoxSelect" dataKey="customerId" [rows]="10" [paginator]="true" paginatorPosition="both" [pageLinks]="5" [rowsPerPageOptions]="[5,10,20]" [globalFilter]="gb" [headerCheckBoxToggleAllPages]="false" [editable]="true" exportFilename="customers" [lazy]="true" [totalRecords]="totalRecords" onLazyLoad)="loadCustomersByPage($event)"
回电功能
$loadCustomersByPage(event: LazyLoadEvent) { const parameters = "?page=" + event.first + "&size=" + (event.first + event.rows); this._cs.findAllActiveCustomerDetailsByPage(parameters).subscribe( (data: any) => { this.customers = data; },(error) => { console.log("--error--" + error) } ); }
解决方法
这是分配给表的数据对象应如下所示:
let cars = [ {"brand": "VW","year": 2012,"color": "Orange","vin": "dsad231ff"},{"brand": "Audi","year": 2011,"color": "Black","vin": "gwregre345"},{"brand": "Renault","year": 2005,"color": "Gray","vin": "h354htr"},{"brand": "BMW","year": 2003,"color": "Blue","vin": "j6w54qgh"},{"brand": "Mercedes","year": 1995,"vin": "hrtwy34"},{"brand": "Volvo","vin": "jejtyj"},{"brand": "Honda","color": "Yellow","vin": "g43gr"},{"brand": "Jaguar","year": 2013,"vin": "greg34"},{"brand": "Ford","year": 2000,"vin": "h54hw5"},{"brand": "Fiat","color": "Red","vin": "245t2s"} ]
我们今天的关于如何解决TypeError:environment.teardown不是函数?和typeerror is not a function的分享就到这里,谢谢您的阅读,如果想了解更多关于Angular 12:如何为每种语言使用单独的 environment.ts 文件(例如 environment.en.ts、environment.de.ts)?、Angular 2 HTTP请求:TypeError:backend.createConnection不是函数、angular – ng-bootstrap typeahead TypeError:Object(…)不是函数、angular – 数据表问题 – ERROR TypeError:val.slice不是函数的相关信息,可以在本站进行搜索。
本文标签: