本文将介绍【IOS】Object-C中的Selector概念的详细情况,特别是关于objective-c的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些
本文将介绍【IOS】Object-C 中的Selector 概念的详细情况,特别是关于objective-c的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于Angular 10:运行 ng xi18n 时无法解析 SomeComponent (?, [object Object], [object Object]) 的所有参数、angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])、ASP.NET list的知识。
本文目录一览:- 【IOS】Object-C 中的Selector 概念(objective-c)
- Angular 10:运行 ng xi18n 时无法解析 SomeComponent (?, [object Object], [object Object]) 的所有参数
- angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])
- ASP.NET list
- discord.js eval 命令返回 [object Map] 和 [object Object]
【IOS】Object-C 中的Selector 概念(objective-c)
|
|
Angular 10:运行 ng xi18n 时无法解析 SomeComponent (?, [object Object], [object Object]) 的所有参数
如何解决Angular 10:运行 ng xi18n 时无法解析 SomeComponent (?, [object Object], [object Object]) 的所有参数
应用运行/构建良好,但是当我尝试运行 List<SubItem> tempSplitFilesList = new ArrayList<>(); List<SubItem> splitFilesList = new ArrayList<>(); for (SubItem item1 : tempSplitFilesList) { for (SubItem item2 : tempSplitFilesList) { if (item1.getStop().equals(item2.getStart())) { splitFilesList.add(item2); } } }
时,我得到 ng xi18n --output-path src/translate
从错误中我可以假设它是导致问题的构造函数中的第一个参数,但是,我的构造函数看起来像这样:
ERROR in Can''t resolve all parameters for SomeComponent in /path/some.component.ts: (?,[object Object],[object Object]).
被扩展的类的构造函数如下所示:
constructor(
$window: Window,service1: Service1,service2: Service2
) {
super($window,service1,Service2);
}
似乎这些错误通常来自注射和/或放置在枪管中的问题?如果是这样,window 是如何在这里出错的,或者它可能是完全不相关的东西?
解决方法
问题似乎与错误注入 Window 一样简单。编写一个自定义服务来处理它解决了这个问题。您可以在这里找到正确的注入方式:How to inject window into a service?
angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])
Can’t resolve all parameters for AuthenticationService: ([object Object],?,[object Object])
我已经检查了几乎每个主题,并尝试了多种方法来解决它,但仍然无法在第二天击败它.
我试图像这样在appService中注入第一个authService但是得到了同样的错误
@Inject(forwardRef(() => AuthenticationService)) public authService: AuthenticationService
我检查了所有DI和服务内部的导入顺序,在我看来一切都是正确的
如果有人可以帮我处理它,我很感激.
Angular 4.0.0
AuthService
import { Injectable } from '@angular/core'; import {Http,Headers,Response} from '@angular/http'; import 'rxjs/add/operator/toPromise'; import {Observable} from 'rxjs/Rx'; import {AppServices} from "../../app.services"; import {Router} from "@angular/router"; @Injectable() export class AuthenticationService { public token: any; constructor( private http: Http,private appService: AppServices,private router: Router ) { this.token = localStorage.getItem('token'); } login(username: string,password: string): Observable<boolean> { let headers = new Headers(); let body = null; headers.append("Authorization",("Basic " + btoa(username + ':' + password))); return this.http.post(this.appService.api + '/login',body,{headers: headers}) .map((response: Response) => { let token = response.json() && response.json().token; if (token) { this.token = token; localStorage.setItem('Conform_token',token); return true; } else { return false; } }); } logout(): void { this.token = null; localStorage.removeItem('Conform_token'); this.router.navigate(['/login']); } }
应用服务
import {Injectable} from '@angular/core'; import {Headers,Http,RequestOptions} from '@angular/http'; import {Router} from "@angular/router"; import {AuthenticationService} from "./auth/auth.service"; import 'rxjs/add/operator/toPromise'; import {Observable} from 'rxjs/Rx'; @Injectable() export class AppServices { api = '//endpoint/'; public options: any; constructor( private http: Http,private router: Router,public authService: AuthenticationService // doesn't work // @Inject(forwardRef(() => AuthenticationService)) public authService: AuthenticationService // doesn't work either ) { let head = new Headers({ 'Authorization': 'Bearer ' + this.authService.token,"Content-Type": "application/json; charset=utf8" }); this.options = new RequestOptions({headers: head}); } // ==================== // data services // ==================== getData(): Promise<any> { return this.http .get(this.api + "/data",this.options) .toPromise() .then(response => response.json() as Array<Object>) .catch((err)=>{this.handleError(err);}) }
应用模块
import { browserModule } from '@angular/platform-browser'; import { browserAnimationsModule } from '@angular/platform-browser/animations'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import {BaseRequestOptions,HttpModule} from '@angular/http'; import { MaterialModule} from '@angular/material'; import {FlexLayoutModule} from "@angular/flex-layout"; import 'hammerjs'; import { routing,appRoutingProviders } from './app.routing'; import { AppServices } from './app.services'; import {AuthGuard} from "./auth/auth.guard"; import {AuthenticationService} from "./auth/auth.service"; import {AppComponent} from './app.component'; import {AuthComponent} from './auth/auth.component'; import {NotFoundComponent} from './404/not-found.component'; import { HomeComponent } from './home/home.component'; @NgModule({ declarations: [ AppComponent,AuthComponent,NotFoundComponent,HomeComponent ],imports: [ browserModule,browserAnimationsModule,FormsModule,HttpModule,routing,MaterialModule,FlexLayoutModule ],providers: [AppServices,AuthGuard,AuthenticationService],bootstrap: [AppComponent] }) export class AppModule { }
解决方法
你可以使用
export class AuthenticationService { public token: any; appService: AppServices; constructor( private http: Http,// private appService: AppServices,injector:Injector; private router: Router ) { setTimeout(() => this.appService = injector.get(AppServices)); this.token = localStorage.getItem('token'); }
另见DI with cyclic dependency with custom HTTP and ConfigService
要避免使用setTimeout,您还可以从AppService的构造函数中设置AuthenticationService.appService(或者相反)
ASP.NET list
public partial class 测试 : System.Web.UI.Page
{
static List<Item> allAnswer= new List<Item>();
protected void Page_Load(object sender, EventArgs e)
{
//首次加载
if (IsPostBack == false)
{
//不能使用将allAnswer中的元素全部删除,这样也会将session中的值清空
//allAnswer.clean();
//使用重新定义新的空的对象来实现对allAnswer的清空
allAnswer = new List<Item>();
List<Item> reallAnswer = null;
try
{
//其中Session["ReAllAnswer"]来自于另一页面
reallAnswer = (List<Item>)Session["ReAllAnswer"];
//PrintAllAnwser(reallAnswer);
}
catch { }
}
}
如果使用allAnswer.clean()函数,则接收的数据Session["ReAllAnswer"]将会设置为空;
而使用new List<Item>(),则不会。
discord.js eval 命令返回 [object Map] 和 [object Object]
如何解决discord.js eval 命令返回 [object Map] 和 [object Object]
所以我有我的 eval 命令,但是当我运行诸如 eval 之类的东西来设置状态或类似的东西时,它会返回 [object Object]
或 [object Map]
。我已经用 [object Promise]
修复了之前的错误,但是仍然会出现 Object 和 Map。我的代码如下,如果有人知道如何解决这个问题,那就太棒了。
if (message.content.startsWith(prefix + "eval")) {
if (message.content === (prefix + ''eval client.token'')) {
const noToken = new discord.MessageEmbed()
.setColor(''RANDOM'')
.setDescription(''OI WHO GAVE YOU PERMISSION TO TOUCH MY TOKEN!!!\\n\\n*back off...*'')
return message.channel.send(noToken)
}
var result = message.content.split(" ").slice(1).join(" ")
let evaled = await eval(result);
const evalEmbed = new discord.MessageEmbed()
.setColor(''RANDOM'')
.addFields(
{ name: ''**Input:**'',value: `\\`\\`\\`js\\n${args}\\`\\`\\``,inline: false },{ name: ''**Output:**'',value: `\\`\\`\\`js\\n${evaled}\\`\\`\\``,inline: false }
)
message.channel.send(evalEmbed)
}
解决方法
好吧,你明白为什么你会得到 [object Object]
和 [object Map]
吗?让我们使用您设置机器人状态的示例。查看文档以了解 setStatus()
返回的内容。根据{{3}},它返回Promise<Presence>
。
问题
你提到你“解决”了它返回一个 Promise
,我假设你的意思是你使用 async/await
来获得 Promise
的结果而不是获得 {{ 1}} 本身。所以基本上,在状态示例中,因为您使用的是 Promise
,所以您不再获得 await
,但您现在获得的是 Promise
对象,这是成功的结果Presence
(如文档所述,当它说 Promise
返回 setStatus()
时)。
好的,这意味着您的 Promise<Presence>
变量现在代表该 evaled
对象。所以 Presence
是一个 evaled
,而不是一个 Object
;它不是您可以在消息中发送或嵌入的一行文本。当您尝试将 String
视为文本(Object
)时,您的代码将尝试将 String
转换为 Object
得到:String
。当然,[object Object]
也是如此,因为它也不是 Map
。
当您使用 String
命令时,结果可以是任何数据类型。例如,如果您执行 eval
,则会返回 /eval 33
。如果您执行 Number
将返回 /eval message.channel.name
,因为频道的名称将是文本。但是,例如,如果您执行 String
,您将不会得到一个简单的数字或一段文本。你会得到一个 /eval client.user.setStatus()
,这就是你的问题的原因。
由于 Object
命令可以返回 any 数据类型的结果,我们需要考虑不能转换为一段文本的数据类型或将被转换的数据类型转换成一段我们没有预料到的文本,就像对象一样。
此外,我在您的代码中注意到 eval
命令的唯一限制是用户无法访问或修改您的机器人的令牌。 根本不要让用户访问 eval 命令。通过 eval
命令可能比简单地访问您的令牌更糟糕。用户可以做任何事情,从故意导致错误使您的机器人崩溃,到创建一个新的消息处理程序,自动删除在您的机器人所在的所有公会中发送的每条消息。此外,由于您的代码现在是这样,用户仍然可以执行 {{ 1}} 并弄乱您的令牌,只需在该行的末尾添加一个分号即可。这个与 eval 命令限制有关的问题不是导致问题的原因,但您需要解决它或冒着为用户提供一种简单的方法来伤害您的机器人、您的机器人所在的公会和/或这些公会的成员的风险.如果此机器人本地托管在您的计算机上,则不要将此命令仅限于您自己,甚至可以授予用户访问您计算机上的文件的权限。
解决方案
以下是我建议您更改 eval 命令的方式,这样它既可以部分解决您的问题,又可以防止用户做任何恶意操作。
eval
这肯定会解决您的 eval client.token
问题(它现在将改为 JSON 字符串,例如 if (message.content.startsWith(prefix + "eval")) {
if (message.author.id != "add YOUR discord id here") {
//Only allow bot developer(s) to use the eval command,not all users
const noToken = new Discord.MessageEmbed()
.setColor(''RANDOM'')
.setDescription(''OI WHO GAVE YOU PERMISSION TO USE EVAL!!!\\n\\n*back off...*'')
return message.channel.send(noToken)
}
var result = message.content.split(" ").slice(1).join(" ")
let evaled = await eval(result);
//Convert evaled into a JSON String if it is an Object
if (typeof evaled === "object") evaled = JSON.stringify(evaled);
//Do this if evaled is anything else other than a number,text,or true/false
if (typeof evaled !== "number" && typeof evaled !== "string" && typeof evaled !== "boolean") evaled = `Output could not be converted to text (output was of type: ${typeof evaled}).`;
const evalEmbed = new Discord.MessageEmbed()
.setColor(''RANDOM'')
.addFields(
{
name: ''**Input:**'',value: `\\`\\`\\`js\\n${args}\\`\\`\\``,inline: false
},{
name: ''**Output:**'',value: `\\`\\`\\`js\\n${evaled}\\`\\`\\``,inline: false
}
);
message.channel.send(evalEmbed)
}
)。不过,我不确定它是否能够将 [object Object]
转换为 JSON。其他任何无法轻松转换为文本的内容(除了数字、布尔值、文本、对象和数组)都将简单地转换为消息,内容如下:{"key": "value"}
您可以随意更改此代码,但您希望它的外观和效果最适合您。输出应如何查找您的特定输入完全取决于您。重要的是您要了解这个答案的概念:使用 Map
检查将被转换为类似 "Output could not be converted to text (output was of type: <insert datatype here>)."
的特定数据类型,并将该数据转换为更好、更易读的数据。
而且我想重复一下将这个命令的使用限制为只有你,或者直接在这个机器人上工作的任何其他人的重要性。 eval 命令的目的是让机器人开发人员更轻松地解决其代码中的问题,允许他们测试某些变量和属性的值,而不必重新启动机器人并typeof
这些值。但是,让所有用户都可以访问此命令会打开数百种不同的方式,让用户可以对公会、成员、您的机器人甚至您采取恶意行动。
关于【IOS】Object-C 中的Selector 概念和objective-c的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于Angular 10:运行 ng xi18n 时无法解析 SomeComponent (?, [object Object], [object Object]) 的所有参数、angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])、ASP.NET list的相关知识,请在本站寻找。
本文标签: