我想知道在创建Angular services时,关于连接services的模块应该考虑什么。
例如
var app = angular.module('app', []);
//Add service to app module
app.factory('helloWorld', function() {
return {};
});
//Or create a module for the service, and include the module where needed
var helloWorldModule = angular.modul
在我的项目中,我创建了一个自定义类型MyType。我想在多个角度模块中使用它,但我不确定正确的方法。我最初的猜测是创建一个公开自定义类型的服务,但这似乎有点过于复杂了。下面我有我的这个方法的演示代码,可以在上找到一个现场演示。
有更好的办法吗?我希望将内容保存在模块中,因此我不希望将自定义类型公开为全局类型。
定义具有自定义类型的服务:
//this code is in file myproject.js
(function(angular, undefined) {
//custom type
function MyType(name) {
this.name = name
同样的代码也适用于angular 8,但现在它给出了这个错误。“无法通过依赖注入创建类'BaseService‘,因为它没有角度装饰器。这将导致在运行时出错。
Either add the @Injectable() decorator to 'BaseService', or configure a different provider (such as a provider with 'useFactory')."
我只是想在这里实现简单的继承。
1) BaseService.ts (父类)
import { environment } fr