我尝试从仅适用于Twitter的身份验证中接收一个accessToken,但仍不断收到来自Twitter API的405(不允许使用方法)响应。有人知道如何解决这个问题吗?我拼命地卡住了..
我知道以下事实:
-最佳实践是从服务器端执行此操作,但我想在客户端使用angular进行尝试
-X-Requested-With应该从标头中删除
这是我创建的工厂:
twitterServices.factory('Connect', function($http){
var factory = {};
var baseUrl = 'https://api.twitter.com/';
var bearerToken = function(){
var consumerKey = encodeURIComponent('****');
var consumerSecret = encodeURIComponent('****');
var tokenCredentials = btoa(consumerKey + ':' + consumerSecret);
return tokenCredentials;
};
factory.fetchAccessToken = function(scope){
var oAuthurl = baseUrl + "oauth2/token";
var headers = {
'Authorization': 'Basic ' + bearerToken(),
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
};
$http.defaults.useXDomain = true;
delete $http.defaults.headers.common['X-Requested-With'];
$http({method: 'POST', url: oAuthurl, headers: headers, data: 'grant_type=client_credentials'}).
success(function(data, status){
scope.status …Run Code Online (Sandbox Code Playgroud) 我正在考虑为$ http服务添加一个默认标头,该值是一个访问标记,将在用户验证后生成.
module.config('$routeProvider', '$locationProvider', '$httpProvider'){
$httpProvider.defaults.headers.post['XSRF-AUTH'] =
"some accessToken to be generated later";
}
Run Code Online (Sandbox Code Playgroud)
问题是,config()当Angular引导其核心组件时应用该块.有没有办法$?ttpProvider动态改变?
在Restangular中,如果我声明一个服务,并执行PUT/PATCH/POST操作,它默认使用项目的id作为主键.但是,如果我们想使用自定义密钥呢?像slu or还是数字?
// GET to /users
Users.getList().then(function(users) {
var user = users[0]; // user === {id: 1, number: 123456, name: "Tonto"}
user.name = "Gonto";
// PUT to /users/1 <-- Here the id is used. But I'd like to use number to post to PUT to /users/123456
user.put();
})
Run Code Online (Sandbox Code Playgroud) 我有点新角.我已经建立了"员工搜索"服务模块.这是代码......
// Service for employee search
app.service('employeeSearchService', function($http, resourceServerAddress){
this.empList = [];
// Method for clearing search employee list
this.clearEmpList = function(){
this.empList = [];
}
// Method for fetching employee search list
this.fetchEmpList = function(){
return this.empList;
}
// Method for making employee search
this.searchEmpList = function(empName){
var postData = {
empName:empName,
};
$http({
method: 'POST',
url: resourceServerAddress,
data : postData
}).then(function successCallback(response) {
console.log('Response Data : '+response);
if(response['data']['status'] === 'success'){
console.log('Response received successfully with status=success');
if(response['data']['data'].length)
{
console.log('matches …Run Code Online (Sandbox Code Playgroud) 在角度2中创建动态组件时,我发现此过程需要ViewContainerRef才能将新创建的组件添加到DOM.
Angular 2动态选项卡,用户单击所选组件 https://www.lucidchart.com/techblog/2016/07/19/building-angular-2-components-on-the-fly-a-dialog-box-example/
在将输入和输出传递给那些动态创建的组件时,我在上面的第二个链接中找到了答案:https: //codedump.io/share/kQakwDKNu0iG/1/passing-input-while-creating-angular-2-组件的动态使用-componentresolver
但是,如果我要创建一个名为shape.service的服务,其中包含使用bgColor等输入返回不同形状组件的函数,我不知道该服务如何在不指定DOM位置的情况下创建组件,以及容器组件如何接收这个返回的组件(可能是它的类型将是ComponentRef)来自服务并将其注入DOM容器组件指定.
例如,服务包含一个功能:
getCircle(bgColor:string): ComponentRef<Circle> {
let circleFactory = componentFactoryResolver.resolveComponentFactory(CircleComponent);
let circleCompRef = this.viewContainerRef.createComponent(circleFactory);
circleCompRef.instance.bgColor = bgColor;
return circleCompRef;
}
Run Code Online (Sandbox Code Playgroud)
第一个问题在这里提出,我如何ViewContainerRef在此期间指出无处?我导入viewContainerRef的原因是动态创建组件.
第二个问题是容器组件@Input从服务接收特定于输入的内容后,它将如何注入其DOM?
提前致谢!
更新: 我认为上面的问题不够具体.我遇到的情况是:
这意味着服务调用组件不知道这些componentRef将被注入的位置.简而言之,我需要可以随时随地注入的独立组件对象.
我已经好几次读过rumTimeCompiler解决方案,但我真的不知道它是如何工作的.与使用viewContainerRef创建组件相比,似乎有太多工作要做.如果我找不到其他解决方案,我会深入研究一下......
我一直在使用离子2 原生sqlite插件制作一个基本的应用程序来捕捉和存储图像到手机本地存储.当我在genymotion模拟器上运行应用程序时,我不断收到未捕获的异常错误(似乎来自sql插件).
当我使用-live参数(离子运行android -c -l)时,应用程序重新加载时通常会发生这种情况.我还注意到存储在应用程序中的数据没有出现(这再次表明在"实时重新加载"时加载存储的数据存在一些问题)我把错误放在控制台下面:
控制台错误消息
[13:28:27] Starting 'html'...
[13:28:27] Finished 'html' after 42 ms
HTML changed: www/build/pages/home/home.html
HTML changed: www/build/pages/map-detail-component/map-detail-component.html
HTML changed: www/build/pages/map-page/map-page.html
0 298305 log Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode.
1 298474 group EXCEPTION: Error: Uncaught (in promise): ReferenceError: sqlitePlugin is not defined
2 298475 error EXCEPTION: Error: Uncaught (in promise): ReferenceError: sqlitePlugin is not defined
3 298476 error STACKTRACE:
4 298477 error Error: Uncaught (in promise): …Run Code Online (Sandbox Code Playgroud) 为什么sort函数工作正常:
<th (click)="sort('transaction_date')">Transaction Date <i class="fa" [ngClass]="{'fa-sort': column != 'transaction_date', 'fa-sort-asc': (column == 'transaction_date' && isDesc), 'fa-sort-desc': (column == 'transaction_date' && !isDesc) }" aria-hidden="true"> </i></th>
Run Code Online (Sandbox Code Playgroud)
当这一个不工作时:
<th (click)="sort('user.name')">User <i class="fa" [ngClass]="{'fa-sort': column != 'user.name', 'fa-sort-asc': (column == 'user.name' && isDesc), 'fa-sort-desc': (column == 'user.name' && !isDesc) }" aria-hidden="true"> </i></th>
Run Code Online (Sandbox Code Playgroud)
HTML
<tr *ngFor="let inner of order.purchase_orders | orderBy: {property: column, direction: direction}">
<td>{{ inner.transaction_date | date }}</td>
<td>{{ inner.user.name }}</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
TS
sort(property){
this.isDesc = !this.isDesc; //change the direction
this.column = …Run Code Online (Sandbox Code Playgroud) 我试图在我的角应用程序中集成谷歌云存储,它导致了这个错误
当我启动我的服务到构造函数
这是我正在使用的服务:
import { Injectable } from '@angular/core';
import { AngularFirestore, AngularFirestoreCollection,
AngularFirestoreDocument } from 'angularfire2/firestore';
import { Idata } from '../model';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class DataService {
// collections initialisation
datas: Observable<Idata[]>;
dataCollection: AngularFirestoreCollection<Idata>;
dataDocumment: AngularFirestoreDocument<Idata>;
data: Observable<Idata>;
constructor(public afs: AngularFirestore) {
}
// get all documents for caucus
getDataCaucus() {
this.dataCollection = this.afs.collection('eluCC');
this.datas = this.afs.collection('eluCC').snapshotChanges().map(changes => {
return changes.map(a => {
const data = a.payload.doc.data() as Idata;
data.id = a.payload.doc.id; …Run Code Online (Sandbox Code Playgroud) 我正在从服务中获取数据,我对订阅后取消订阅很重要,这是我的做法:
export class RItemComponent implements OnInit {
apiPath = environment.apiUrl;
private ngUnsubscribe: Subject = new Subject();
constructor(private _sharedService: SharedService) { }
rItems: Product[];
ngOnInit() {
this._sharedService.
getReceiptItem().takeUntil(this.ngUnsubscribe).
subscribe(products => this.rItems = products);
}
ngOnDestroy() {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}
}
Run Code Online (Sandbox Code Playgroud)
但是现在我得到一个错误:
泛型类型Subject需要1个类型参数。订阅
我不明白为什么?
任何帮助都会很棒,谢谢!
Angular的新手。我的应用程序包含1个服务和3个组件。编译成功。我收到此错误,不知道出了什么问题:
未捕获的错误:无法解析ApplicationModule的所有参数:(?)。
调试给我的想法很少。似乎问题与具有空依赖项的NSLocaleLocalizations有关(如果可以的话)-请参见以下屏幕截图:

这是一些代码:如果需要其他任何信息,请告诉我。非常感谢您的帮助-非常感谢。
package.json
{
"name": "angular_app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build-aot": "ng build --prod --aot",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.0.0",
"@angular/cdk": "^6.0.0",
"@angular/common": "^6.0.0",
"@angular/compiler": "^6.0.0",
"@angular/core": "^6.0.0",
"@angular/forms": "^6.0.0",
"@angular/http": "^6.0.0",
"@angular/material": "^6.0.0",
"@angular/platform-browser": "^6.0.0",
"@angular/platform-browser-dynamic": "^6.0.0",
"@angular/router": "^6.0.0",
"core-js": "^2.5.4",
"express": "^4.16.4",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "^6.0.0",
"@angular-devkit/build-angular": "~0.6.0",
"typescript": "~2.7.2",
"@angular/cli": "~6.0.0", …Run Code Online (Sandbox Code Playgroud) angular-services ×10
angular ×6
angularjs ×4
javascript ×2
angular-dependency-injection ×1
angular-pipe ×1
http-headers ×1
ionic2 ×1
restangular ×1
rxjs ×1
sqlite ×1
twitter ×1
typescript ×1