gpt4 book ai didi

javascript - AngularJS/Sqlite/Electron - 未知提供者 : $dbServiceProvider

转载 作者:行者123 更新时间:2023-11-30 13:54:20 25 4
gpt4 key购买 nike

我正在尝试构建 Electron 应用程序,它从我创建的 SQL 数据库中显示/检索表中的项目,但出现未知提供程序错误。

我尝试了网上的一些解决方案,但问题仍然存在,我不知道哪里做错了

这是我连接到数据库的 Angular 服务 (dbService.js)

app.factory("dbService", function ($http) {
var sqlite = require('sqlite-sync');
var db = sqlite.connect('model/database.db');
return db;
});

这是我的 Controller (salesController.js)

app.controller("salesController", function ($scope, $location, $dbService) {
$scope.sub = {
'title': 'Sales Management'
}

$scope.listSales = function () {
dbService.runAsync("SELECT * FROM sales WHERE active = 1", function (data) {
$scope.sales = data;
});
}

});

这是我的模块 (app.js)

var app = angular.module('bpApp', ['ui.router', 'angularUtils.directives.dirPagination']);

最后我添加了这段代码来将数据显示到我的表 (sales.html)

....
<tbody>
<tr class="bz-tablecell" dir-paginate="sale in sales|filter:search|itemsPerPage:8">
<td id="table-checkbox"><input type="checkbox"></td>
<td style="font-weight: 600">{{sale.name}}</td>
<td>{{sale.amount}}</td>
<td>{{sale.quantity}}</td>
<td><a href="#">{{sale.customer}}</a></td>
<td>{{sale.date}}</td>
<td class="export-ignore"><span class="approved" style="border-radius: 0 !important;">{{sale.status}}</span></td>
<td class="export-ignore"><a href="#">Manage</a></td>
</tr>
</tbody>
...

我已经在我的 index.html 中包含了所有需要的文件,然后通过 ui-view 加载 sale.html,加载 View 没问题,但是没有从我的数据库中检索数据,我不断收到错误:

Error: [$injector:unpr] Unknown provider: $dbServiceProvider <- $dbService <- salesController

请帮我解决一下...

最佳答案

尝试将 Controller 的声明更改为

app.controller("salesController", function ($scope, $location, dbService) {

你的 dbService 工厂不是 AngularJS API,它有 $ 前缀,这就是它不能注入(inject)它的原因。

请引用https://docs.angularjs.org/guide/concepts#angular_namespace

$' Prefix Naming ConventionYou can create your own services, and in fact we will do exactly that in step 11. As a naming convention, angular's built-in services, Scope methods and a few other angular APIs have a '$' prefix in front of the name. Don't use a '$' prefix when naming your services and models, in order to avoid any possible naming collisions.

Angular NamespaceTo prevent accidental name collision, Angular prefixes names of objects which could potentially collide with $. Please do not use the $ prefix in your code as it may accidentally collide with Angular code.

关于javascript - AngularJS/Sqlite/Electron - 未知提供者 : $dbServiceProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57600383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com