问题是由Safari中使用的默认类型检测器引起的。在更新到Angular v15之后,您需要手动引入polyfill来解决。
要解决这个问题,请在src/polyfills.ts文件中添加以下代码:
(window as any).__type = (value: any) => {
try {
return {}.toString.call(value).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
} catch (err) {
return typeof value;
}
};
然后在angular.json文件的build选项中添加以下内容:
{
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"allowedCommonJsDependencies": ["typescript"],
"assets": ["src/favicon.ico", "src/assets"],
"outputPath": "dist/example",
"index": "src/index.html",
"polyfills": "src/polyfills.ts",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json"
},
"configurations": {
...
"production": {
...
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": {
"scripts": true,
"styles": {
"minify": true,
"inlineCritical": true
}
},
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
},
...
}
}
}
现在重新构建应用程序即可在Safari中正常工作。