我正在尝试使用从Web服务检索的数据来更新Angular 6(更新:现在的Angular 7)Universal应用程序(使用Meta和Title)中的元数据.我专门为Twitter和Facebook卡做这个.我知道他们的抓取工具不执行JavaScript,这就是我使用Angular Universal在服务器端设置元数据的原因.我正在使用Facebook共享调试工具来检查结果.
我尝试了几种不同的方法,并且我已经找到了示例,但是我没有找到一个在设置元数据之前从对Web服务的异步调用中检索数据的方法.(请注意,我在Angular Universal 4应用程序中成功使用此服务与Web服务.)
使用下面的代码,"og:url"标记被正确设置为不需要Web服务调用来获取数据.但是,标题未正确设置.如果我将"setTitle"调用移动到ngOnInit并提供一个字符串,那就可以了 - 但是从Web服务获取数据却没有.
我尝试使用服务来收集数据,然后设置元数据,但这也不起作用.我从解析器获取数据,但它没有解决Facebook/Twitter问题.
ngOnInit() {
const metaUrl = 'https://www.test.com' + this._router.url;
this._metaService.updateTag({ property: 'og:url', content: metaUrl });
this._sub = this._route.params.subscribe(params => {
const code = params['person'];
this.getInfo(code);
});
}
getInfo(code: string) {
this._myWebService.getPerson(code).subscribe(
data => {
this._person = data;
// set dynamic metadata
const metaTitle = this._person.name + ' | site description';
this._titleService.setTitle(metaTitle);
this._metaService.updateTag({ name: 'twitter:title', content: metaTitle });
});
}
Run Code Online (Sandbox Code Playgroud)
更新:我还尝试使用解析器首先获取数据,以便我可以在onInit中使用它.它不起作用.
{ path: 'view/:person', component: ViewComponent,
resolve: { person: …
Run Code Online (Sandbox Code Playgroud) 我想将单引号(')替换为双引号(“),以使其在 python 数据框中正确的 json 列值。
例如 csv 文件看起来像...
Unit Id Batch Id Items prod
A108 qa120 {'A': 123, 'B': 342, 'C': 454}
P258 re015 {'A': 124, 'B': 234, 'C': 343}
Run Code Online (Sandbox Code Playgroud)
我正在从 csv 读取这些值到 pandas 数据帧。我尝试了几种方法,但没有成功。
df.replace("'",'"',inplace=True)
df.['<column_name>'].str.replace(r"[\',]",'"')
df = df['<column_name>'].str.replace(r"[\',]",'"')
Run Code Online (Sandbox Code Playgroud)
提前感谢您的帮助。
我的构建在 Windows 10 上一直失败,无法在 anaconda 中安装 fbprophet,并显示以下消息:
ERROR conda.core.link:_execute(502): An error occurred while installing package 'conda-forge::automat-0.7.0-py_1'.
CondaError: Cannot link a source that does not exist. C:\Users\bharat.c.ruparel\AppData\Local\Continuum\anaconda3\Scripts\conda.exe
Run Code Online (Sandbox Code Playgroud)
给出的命令是:
conda install -c conda-forge fbprophet
有没有人在 Windows 10 上成功安装过 fbprophet?如果是,请给出步骤。
谢谢。我也试过 pip install 但没有运气。我有一台 Mac 并设法在其上安装了 fbprophet,没有任何问题。
我想在Angular 7中的两条路线之间导航,并在它们之间发布数据.但我不想在URL中显示这些参数.如何以正确的方式做到这一点?
在这一刻,我正在遭遇这样的事情:
this.router.navigate(['/my-new-route', {data1: 'test', test2: 2323, test: 'AAAAAAA'}]);
它改变了我的网址
http://localhost:4200/my-new-route;data1=test;test2=2323;test=AAAAAAA
如何从URL中取消这些数据:
http://localhost:4200/my-new-route
编辑:
我的情况:
on/form route - 用户有一些带有空字段的表单可以手动填写
但在/ options页面上有一些预设配置,当用户选择一个导航到/表格并且字段自动填充时
当他们移回另一页并再次返回/表格时 - 应该看到空表格.只有/ options到/ form的链接才能填充这些字段.
较新版本的 Conda 为用户提供了有关导致与环境冲突的不一致包的更多详细信息。我的 conda env 中的一个这样的包是_nb_ext_conf
根据 anaconda cloud,它是我系统中安装的最新 0.4.0,即使如此,我在尝试安装/更新模块时也会收到此警告:
The environment is inconsistent, please check the package plan carefully
The following packages are causing inconsistency:
- defaults/osx-64::_nb_ext_conf==0.4.0=py36_1
Run Code Online (Sandbox Code Playgroud)
无法删除此包,因为 jupyterlab 和 notebook 都需要它。我不确定它是否会导致严重的冲突,因为我还没有遇到任何损坏的情况,但我仍然想解决这种不一致的问题。有什么办法可以修复它吗?我在 github 的 conda 问题部分搜索了类似的问题,但没有遇到任何类似的问题。
我在端口4202中提供了角度应用程序,并通过以下代码连接到remove spring mvc应用程序。
this.http.post<Hero[]>('http://localhost:8080/api/hero/list', {"id":1}, httpOptions)
Run Code Online (Sandbox Code Playgroud)
但是它报告了以下错误。
Failed to load http://localhost:8080/api/hero/list: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4202' is therefore not allowed access. The response had HTTP status code 403.
Run Code Online (Sandbox Code Playgroud)
因此,我尝试通过控制器方法下的注释在我的spring Web应用程序中启用cors。
@CrossOrigin(origins = "http://localhost:4202")
Run Code Online (Sandbox Code Playgroud)
我还尝试添加如下配置类。
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
}
}
Run Code Online (Sandbox Code Playgroud)
然后刷新下面的前端用户界面。
Failed to load http://localhost:8080/api/hero/list: The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:4202, *', but …
Run Code Online (Sandbox Code Playgroud) 我收到致命错误:CALL_AND_RETRY_LAST分配失败 - Angular 7.1升级后JavaScript堆内存不足.以前的版本6.1工作得非常好.
我在运行ng build --prod
命令时仅在Azure DevOps中收到错误.它在当地建造完美.
以下是详细日志.知道我为什么会收到这个错误吗?
2018-11-22T06:40:36.2804965Z ##[section]Starting: npm build
2018-11-22T06:40:36.2809301Z ==============================================================================
2018-11-22T06:40:36.2809365Z Task : npm
2018-11-22T06:40:36.2809456Z Description : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Package Management.
2018-11-22T06:40:36.2809496Z Version : 1.0.27
2018-11-22T06:40:36.2809531Z Author : Microsoft Corporation
2018-11-22T06:40:36.2809612Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613746)
2018-11-22T06:40:36.2809648Z ==============================================================================
2018-11-22T06:40:36.7158800Z SYSTEMVSSCONNECTION exists true
2018-11-22T06:40:36.8019327Z SYSTEMVSSCONNECTION exists true
2018-11-22T06:40:36.8872807Z [command]C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files\nodejs\npm.cmd" --version"
2018-11-22T06:40:37.5174051Z 6.4.1
2018-11-22T06:40:38.9461529Z …
Run Code Online (Sandbox Code Playgroud) 我开发了一个带有后端的angular 7应用程序。Express在Angular上运行,localhost:3000
而Angular Client在localhost:4200上运行。
在server.js
我有(不是整个代码)
const app = express();
// Enable CORS
app.use(cors());
// Get our API routes
const api = require('./api');
// Set our api routes
app.use('/api', api);
app.use(express.static(__dirname + '/dist/sfdc-event'));
Run Code Online (Sandbox Code Playgroud)
在api.js文件中,我有router.get('/ oauth2 / login')重定向到https://example.com,后者发送访问令牌并验证用户身份(OAuth2身份验证)。
当我调用URL http:// localhost:3000 / api / oauth2 / login时,一切正常,但是当我尝试从angular component.ts-> service.ts中执行相同操作时,出现以下错误。
跨域请求被阻止:同源策略禁止读取远程资源原因:CORS标头“ Access-Control-Allow-Origin”丢失
Angular应用程序流程如下login.component.ts,它具有一个调用服务api.service.ts的按钮,该按钮执行http get。
login.component.ts
sfdcLogin(): void {
console.log('DEBUG: LoginComponent: ', 'Login button clicked..');
this.apiService.login().subscribe( data => { console.log( data ); });
}
Run Code Online (Sandbox Code Playgroud)
api.service.ts
login() {
console.log('DEBUG: …
Run Code Online (Sandbox Code Playgroud) 我正在使用Angular 7。
我试图在Typescript上使用fs模块打开目录。我总是遇到以下错误:“未找到模块:错误:无法解析fs”类型@节点和文件系统已安装。
我的代码:
import {Component, OnInit} from '@angular/core';
import * as fs from 'file-system';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'my-app';
constructor() {
}
ngOnInit() {
console.log(fs);
}
}
Run Code Online (Sandbox Code Playgroud)
你能帮助我吗 ?
节点:v10.14.0 Npm:v6.4.1 Angular CLI:v7.1.1
我需要的初始位置cdk-virtual-scroll-viewport
不是列表的第一个元素/项目。
现在我找到了scrollToIndex
和scrollTo
方法,但我只能在 中使用它时才能让它们工作ngAfterViewChecked
,这感觉不对。
ngAfterViewChecked
是正确的做事方式吗? @ViewChild(CdkVirtualScrollViewport) cdkVirtualScrollViewport: CdkVirtualScrollViewport;
numbers: number[] = [];
constructor() {
for (let index = 0; index < 10000; index++) {
this.numbers.push(index);
}
}
ngAfterViewChecked() {
this.cdkVirtualScrollViewport.scrollToIndex(2000);
}
Run Code Online (Sandbox Code Playgroud)
<ul class="list">
<cdk-virtual-scroll-viewport style="height:264px" itemSize="88">
<ng-container *cdkVirtualFor="let n of numbers">
<li style="height:88px">{{ n }}</li>
</ng-container>
</cdk-virtual-scroll-viewport>
</ul>
Run Code Online (Sandbox Code Playgroud)
angular ×7
angular7 ×7
python ×3
anaconda ×2
conda ×2
typescript ×2
angular-cdk ×1
azure-devops ×1
cors ×1
dataframe ×1
express ×1
fs ×1
javascript ×1
lifecycle ×1
metadata ×1
node.js ×1
npm ×1
package ×1
pandas ×1
post ×1
replace ×1
routing ×1
spring-mvc ×1
string ×1
virtualenv ×1
windows ×1