我正在尝试使用通过新的angular CLI创建的Angular2项目中的FB SDK。我创建了以下服务来初始化Facebook库,添加了fbsdk类型并可以编译所有内容,但是除了“ winwow.fbAsyncInit”函数之外,我无法从项目中的任何位置访问FB全局变量。我可以从控制台完美地检查FB对象,但无法从NG2代码访问它。¿任何关于问题可能出在哪里的想法?
import { Injectable, OnInit } from '@angular/core'
import { FACEBOOK_APPID } from '../constants'
@Injectable()
export class fbService implements OnInit{
constructor(){}
ngOnInit(){
if (!window.fbAsyncInit) {
window.fbAsyncInit = function () {
FB.init({
appId: FACEBOOK_APPID,
xfbml: false,
version: 'v2.6'
});
FB.api("/me",null,()=>{})
console.log(FB)
};
}
this.initFB()
}
initFB(){
var js, id = 'facebook-jssdk', ref = document.getElementsByTagName('script')[0];
if (document.getElementById(id)) {
return;
}
js = document.createElement('script');
js.id = id;
js.async = true;
js.src = "//connect.facebook.net/en_US/sdk.js";
ref.parentNode.insertBefore(js, ref);
}
getPost(page:string){
FB.api(`/${page}/feed?limit=1`,null,(response)=>{console.log(response)})
}
}
Run Code Online (Sandbox Code Playgroud) 我想在我的Angular 2应用程序中添加一些碎片样式,比如将在每个地方使用的字体和颜色方案.在过去,我总是通过向我的索引页面添加这样的标记来完成此操作:
<link rel="stylesheet" href="css/framework.css" />
Run Code Online (Sandbox Code Playgroud)
这不适用于CLI用于提供应用程序的任何内容.我尝试在构建之后手动将css文件添加到dist文件夹,但这似乎也不起作用.
我也尝试在这样的anugular-cli-build.js文件夹中添加css
module.exports = function(defaults) {
return new Angular2App(defaults, {
vendorNpmFiles: [
'css/*.css'
]
});
};
Run Code Online (Sandbox Code Playgroud)
css当我告诉它构建时,它似乎仍然没有在文件夹中构建文件.
有问题的样式表是整个应用程序的基线样式,而不是我想要包含在styleUrl标记中的样式.
我曾经有角度cli,但我错误地再次安装它
npm install -g angular-cli
Run Code Online (Sandbox Code Playgroud)
现在,当我运行ng serve它抱怨:
It seems like you're using a project generated using an old version of the Angular CLI.
The latest CLI now uses webpack and includes a lot of improvements, include a simpler
workflow, a faster build and smaller bundles.
To get more info, including a step-by-step guide to upgrade the CLI, follow this link:
https://github.com/angular/angular-cli/wiki/Upgrading-from-Beta.10-to-Beta.12
Run Code Online (Sandbox Code Playgroud)
当我尝试ng new在另一个目录中创建一个新项目时 ,它会抱怨:
Cannot find module 'reflect-metadata'
Run Code Online (Sandbox Code Playgroud)
那么问题是什么?
Windows服务器2012 R2
node v4.7.4 npm v4.3.0
我不能做"服务":"/ c/Users // AppData/Roaming/npm/ng:没有这样的文件或目录"
我也不能做"npm start":"意外令牌{"然后是一个巨大的调用栈.
我尝试过使用各种版本的node/npm/cli等...我无法到达任何地方.
我的应用程序的project.json文件:
{
"name": "my-proj",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"start": "ng serve --env=source",
"build": "ng build",
"build-replace": "ng build --env=replace",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/common": "2.0.0",
"@angular/compiler": "2.0.0",
"@angular/compiler-cli": "2.2.4",
"@angular/core": "2.0.0",
"@angular/flex-layout": "2.0.0-beta.3",
"@angular/forms": "2.0.0",
"@angular/http": "2.0.0",
"@angular/material": "2.0.0-alpha.10",
"@angular/platform-browser": "2.0.0",
"@angular/platform-browser-dynamic": "2.0.0",
"@angular/router": "3.0.0",
"angular2-select": "1.0.0-alpha.12",
"core-js": "2.4.1",
"hammerjs": "2.0.8", …Run Code Online (Sandbox Code Playgroud) ng -v:1.0.0-beta.32.3
"devDependencies": {
"@angular/compiler-cli": "2.4.4",
"@types/jasmine": "^2.5.38",
"@types/node": "^6.0.42",
"codelyzer": "~2.0.0-beta.4",
"jasmine-core": "^2.5.2",
"jasmine-spec-reporter": "^3.2.0",
"karma": "^1.4.1",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.1.0",
"karma-phantomjs-launcher": "^1.0.2",
"karma-remap-istanbul": "^0.6.0",
"protractor": "^4.0.13",
"ts-node": "~2.0.0",
"tslint": "^4.4.2",
"typescript": "~2.0.3"
}
Run Code Online (Sandbox Code Playgroud)
/tslint.json
{
"rulesDirectory": [
"node_modules/codelyzer"
],
"rules": {
"class-name": true,
"comment-format": [
true,
"check-space"
],
"curly": true,
"eofline": true,
"forin": true,
"indent": [
true,
"spaces"
],
"label-position": true,
"max-line-length": [
false,
140
],
"member-access": false,
"member-ordering": [
true,
"static-before-instance"
],
"no-arg": true,
"no-bitwise": true, …Run Code Online (Sandbox Code Playgroud) 我正在尝试将本地开发的Angular项目/模块导入到angular应用程序中,而不将其发布到npm存储库中。
首先,我按照本教程以UMD格式构建模块(我跳过了发布部分):
https://medium.com/@cyrilletuzi/how-to-build-and-publish-an-angular-module-7ad19c0b4464
然后,我尝试通过执行以下命令行在最终应用程序中安装模块:
npm install ../path-to-my-module --save
Run Code Online (Sandbox Code Playgroud)
这成功添加我的模块,@myscope/myModule在package.json我的应用程序,但问题是,在应用程序模块的进口无法识别。我最终收到以下错误:
Cannot find module @myscope/myModule
Run Code Online (Sandbox Code Playgroud)
在my中node_modules,@myscope创建了文件夹,并且在其中有一个../path-to-my-module名为的快捷方式myModule
问题的根源是否在于捷径?如果可以的话如何解决?
我做了一个
npm i
npm -g @angular/cli
Run Code Online (Sandbox Code Playgroud)
然后当我这样做
ng serve
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误
但是我把n发送到npm脚本(在package.json中的npm start)它可以工作.
我为我的项目创建了一个包含一些组件和服务的核心库.我用ng-packagr构建了库.在引用库的消费项目中,我构建了包含库提供的组件的webapp.到目前为止没什么特别的.但有时我想要一个组件(来自我的lib)从lib外部的服务调用一个方法.这可能吗?我可以以某种方式将服务注入到库中定义的组件吗?
干杯
我从NG4-> NG6重写库(使用angular-cli 6)。这个lib改变了dynamicli的角度分量,所以我使用了ComponentFactoryResolver,在这里我卡住了。当我添加ComponentFactoryResolver到构造函数中时:
constructor(
private componentFactoryResolver: ComponentFactoryResolver
) {}
Run Code Online (Sandbox Code Playgroud)
并在目标应用程序中构建lib(成功)(我从本地文件中将我的lib添加到package.json中)我遇到此错误:
StaticInjectorError(AppModule)[MyLibComponent-> ComponentFactoryResolver]:
StaticInjectorError(Platform: core)[MyLibComponent-> ComponentFactoryResolver]:
NullInjectorError: No provider for ComponentFactoryResolver!
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:979)
at resolveToken (core.js:1232)
at tryResolveToken (core.js:1182)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1077)
at resolveToken (core.js:1232)
at tryResolveToken (core.js:1182)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1077)
at resolveNgModuleDep (core.js:9238)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:9919)
Run Code Online (Sandbox Code Playgroud)
没有ComponentFactoryResolver其他事情就可以正常工作
完整组成部分:
import { Component, ComponentFactoryResolver, AfterContentInit, ViewChild, Inject, Input, InjectionToken } from '@angular/core';
import { AbHostDirective } from './../directives/ab-host.directive';
export const AB_COMPONENTS = new InjectionToken('AB_COMPONENTS');
@Component({ …Run Code Online (Sandbox Code Playgroud) 我使用升级到Angular 8 ng update。它运行了迁移脚本,该脚本除其他外还删除了中的es6 / es7导入polyfills.ts。根据我的阅读,Angular将为较旧的浏览器(包括IE11)创建一个特殊的版本,而我不必担心polyfills了吗?我更新browserlist为,not IE 9-10而不是not IE 9-11(我认为)暗示它应该构建适当的polyfills。
不幸的是,运行后ng build,出现一些与polyfill相关的错误,例如。Reflect.getMetadata is not a function和Object doesn't support property or method 'includes'。我尝试将reflect其array导入并导入到polyfills中,并克服了这些错误,但是我遇到了其他错误。这是怎么回事?我应该包括polyfills吗?
如何使Angular 8与IE11一起使用?
angular-cli ×10
angular ×9
npm ×3
ng-packagr ×2
angular5 ×1
angular6 ×1
components ×1
css ×1
dynamic ×1
javascript ×1
lint ×1
npm-start ×1
polyfills ×1
typescript ×1