我的服务中有一个功能如下:
export class DualLogonService {
url: string;
constructor(private router: Router) {}
saveURL(): void {
this.url = this.router.url;
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序模块
import { DualLogonService } from './ dual-logon/dual-logon.service';
...
export function saveUrl(dualLogonService: DualLogonService, router: Router) {
console.log(router.url);TypeError: Cannot read property 'url' of undefined
return dualLogonService.saveURL();//TypeError: Cannot read property 'saveURL' of undefined
}
{
provide: APP_INITIALIZER,
deps: [DualLogonService],
useFactory: saveUrl,
multi: true
}
Run Code Online (Sandbox Code Playgroud)
如果我在服务中执行以下操作,则可以在 app.module 中访问该功能,但我无法使用this.router.url:
export function saveURL() {
this.url = this.router.url;
}
Run Code Online (Sandbox Code Playgroud) 我正试图摆脱丑陋的按钮rails作为文件上传的默认值.我想添加一个glyphicon
<%= f.file_field :image_url, class:"glyphicon glyphicon-camera" %>
Run Code Online (Sandbox Code Playgroud)
这不起作用,我在这个页面上看到的不同帖子中尝试了其他的东西,但他们没有附加文件.
我正在使用谷歌地图 API(地理编码),我注意到以下内容。如果我打印“x”地址的数组,它会打印一个大小为 9 的对象数组。其中国家/地区位于索引 6 中。如果我输入其他“y”地址,有时对象数组小于 9 并且获得国家的指数不再是6了。我尝试过使用不同的地址,因为其中一些地址的大小一致为 9,其中一些为 6,另一些为 7,等等。有没有一种固定的方法可以让我访问该国家/地区而无需检查数组的大小并避免此问题?
我的代码
let place: google.maps.places.PlaceResult = autocomplete.getPlace();
this.addressArray = place.address_components;
if(this.addressArray.length === 9) {
this.country = this.addressArray[6].short_name;
this.zipcode = this.addressArray[7].short_name;
} else {
this.country = this.addressArray[5].short_name;
this.zipcode = this.addressArray[6].short_name;
}
Run Code Online (Sandbox Code Playgroud)
我想我可以使用place.formatted_address和访问最后一个单词,它始终是国家/地区,但对于邮政编码和地址上的其他一些信息,顺序并不总是相同。下面是我正在打印的对象数组的结构示例。
我考虑过过滤数组以查找包含单词国家/地区、邮政编码等的类型的索引,并根据返回的索引获取国家/地区或我想要检索的任何内容。我想知道是否有一种更简单的方法可以直接从 google API 地理编码来完成此操作。
这个问题如何从谷歌地图API获取国家/地区?谈论有人输入地址。我的应用程序使用谷歌自动完成功能。我认为 API 可以更智能地处理人们未输入完整地址而丢失的数据。另外,该问题中的答案地址是我对我的问题的解释的一部分,我说我知道我可以过滤数组
我是 MAC 新手(OSX 版本是 High Sierra 10.13.3)。我使用 python.org 的安装程序安装了 python 3.6.5,并且我也尝试通过运行来使用 brew 来完成它brew install python。现在,我尝试sudo npm install在 Angular 项目中运行,但出现以下错误:
gyp verb check python checking for Python executable "/path/to/python3/python" in the PATH
gyp verb `which` failed Error: not found: /path/to/python3/python
gyp ERR! stack Error: Can't find Python executable "/path/to/python3/python", you can set the PYTHON env variable.
Run Code Online (Sandbox Code Playgroud)
我已经尝试过这里的所有答案:
在我的项目文件夹中,我执行以下操作:
当我输入“which python”时,我得到:
/usr/local/opt/python/libexec/bin/python
Run Code Online (Sandbox Code Playgroud)
当我输入“which python3.6.5”时,我得到:
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
Run Code Online (Sandbox Code Playgroud) 自从一年前我遵循本教程以来,我决定在 stackoverflow 中发布问题和答案:https ://www.youtube.com/watch?v=pxyX_5mtlTk 。我试图从 Angular 中的谷歌位置自动完成中检索纬度和经度。我试图用谷歌搜索解决方案,在这里发布问题(没有人回答,所以我删除了我的问题),但我没有运气,最终我能够弄清楚,我决定在 YouTube 教程上发布我知道如何去做吧,从一年前开始,我收到了 35 封电子邮件询问我的解决方案,所以我决定也在这里分享。
我在我的 Angular 应用程序中使用angular-datatables。当数据更改时(例如,填写并提交表单时),我需要刷新数据表。等效的 jQuery 代码是
$('#my-datatable').DataTable.ajax.reload()。
我正在使用 Angular 7。这是我正在使用的库的链接。
所以有多种方法可以在 JS 中转换和转换Array为 a Set。
示例 #2绝对是O(n),因为它遍历数组的所有元素。示例 #1 的情况是否相同?或者JS在后台为我们做一些优化?
如果是,使用Example #1有什么缺点吗?
const arr = [ 1, 3, 2, 3, 5 ];
const set = new Set(arr);
console.log(set);
/*
Output: Set { 1, 3, 2, 5 }
*/
Run Code Online (Sandbox Code Playgroud)
const arr = [ 1, 3, 2, 3, 5 ];
const set = new Set();
arr.map(item => set.add(item));
console.log(set);
/*
Output: Set { 1, 3, 2, 5 }
*/
Run Code Online (Sandbox Code Playgroud) 如您所知,Tailwind 是一种非常流行的 PostCSS 解决方案。我想在运行版本 11.2.0 或旧版本的 Angular 应用程序中添加 TailwindCSS。我怎么能这样做?
我决定发布并回答我自己的问题,因为这是我最近在 Angular 社区看到的一个非常受欢迎的问题
如果你看一下getData()方法,它会说this.http.get<Post>.是<Post>指定返回类型,检查响应类型或转换返回的内容
interface Post {
title: string;
body: string;
};
// ...
constructor(private http: HttpClient) {}
getData() {
this.http.get<Post>(this.url).subscribe(res => {
this.postTitle = res.title;
});
}
Run Code Online (Sandbox Code Playgroud) 我是QR codes从我的 Angular Web 应用程序生成的。我正在使用npm包ngx-qrcode2来生成二维码。
有没有办法用这个npm包或另一个 npm 包JSON在 QR 中存储一个对象。然后读取 QR,并使用 qr reader zxing/ngx-scanner提取 JSON 。
目前,如果我将 JSON 转换为字符串,将该字符串存储在 QR 中,然后当我读取它时,将其解析回JSON.
这是我迄今为止所做的。
angular ×6
google-maps ×2
angular6 ×1
arrays ×1
big-o ×1
css ×1
datatables ×1
javascript ×1
macos ×1
npm ×1
python ×1
qr-code ×1
ruby ×1
set ×1
tailwind-css ×1