我正在使用MySQL 5.5,这就是为什么我不能使用FULLTEXT搜索所以请不要建议它.
我想要做的是,如果用户我有5条记录,例如:
Amitesh
Ami
Amit
Abhi
Arun
Run Code Online (Sandbox Code Playgroud)
如果有人搜索Ami然后它应该首先返回Ami作为完全匹配然后Amit&Amitesh
我已经有一个基于角度1.3.4的应用程序,我想将它更改为角度2但是模块化.
让我说我的页面上有5个模块我想将一个模块迁移到角度2,其他应该像1.3之前一样工作,所以慢慢地我可以转换但是直到它不应该停止工作.
我包括角度2和角度1.3.4库,它说在控制台中没有定义角度
所以我写了这段代码,这一行use(private lang: string): Promise<object>
给了我一个错误“A parameter property in only allowed in constructor implementation”
当我删除访问修饰符时它会起作用,private
但我只是好奇为什么它会给我这个错误以及正确的方法是什么?
@Injectable()
export class TranslateService {
public data: object = {};
constructor(private http: HttpClient) {}
use(private lang: string): Promise<object> {
return new Promise<object>((resolve, reject) => {
const langPath = `assets/i18n/${lang || 'en'}.json`;
this.http.get<object>(langPath).subscribe(
translation => {
this.data = Object.assign({}, translation || {});
resolve(this.data);
},
error => {
this.data = {};
resolve(this.data);
}
);
});
}
}
Run Code Online (Sandbox Code Playgroud) 我的服务:
fetchData(url,request)
{
return this.http.post(this.apiUrl+url,request).subscribe(
(response) => {return response.json()}
);
}
Run Code Online (Sandbox Code Playgroud)
我的组件:
ngOnInit()
{
this.response = this.dataService.fetchData('friends/grow_network',{});
console.log('s ',this.response);
}
Run Code Online (Sandbox Code Playgroud)
如果我在服务中控制台response.json(),它将显示来自api的正确数据,但是如果我在组件中进行控制台,则显示如下:
Subscriber {closed: false, _parent: null, _parents: null, _subscriptions: Array(1), syncErrorValue: null…}
Run Code Online (Sandbox Code Playgroud)
如何获取来自api而不是订户数据的组件中的数据?
我正在使用反应式角度表单并创建了新的自定义表单验证器,但它没有显示自定义消息我想为自定义验证器添加自定义消息。
我试图忽略静态消息我希望将该消息添加到该验证器本身中,以便它可以在我使用该验证器的任何地方显示。
自定义验证器代码:
import { FormControl } from '@angular/forms';
export function validateJson(input: FormControl): object | null {
try {
if (input.value) {
JSON.parse(input.value);
}
return null;
} catch (error) {
return { invalidFormat: true };
}
}
Run Code Online (Sandbox Code Playgroud) javascript typescript angular-validation angular angular-reactive-forms
我有一个名字和数字的数组,如下所示:
$users = array(
"name one"=>"2",
"name two"=>"5.5",
"name three"=>"8",
"name four"=>"7",
"name five"=>"2.5",
"name six"=>"3"
);
Run Code Online (Sandbox Code Playgroud)
现在我想从它做3对,但两个对值必须最接近,例如答案将:
name three pair with name four
name one pair with name five
name two pair with name six
Run Code Online (Sandbox Code Playgroud)
我在php或javascript中找不到任何函数来制作像这样的对或任何相关的有用函数.
如果有相同或类似的功能或任何自定义代码可以实现它,请告诉我