我已经使用了角度全栈发生器很长时间了,我最近更新了它,发现它不再使用bower,并且它使用require来获取客户端中的模块。我的问题是,当我尝试申报服务时,我无法理解这是如何工作的。
如果我运行,例如,example.service.js
它会在client/app/example
路径中使用以下代码创建'use strict';
const angular = require('angular');
/*@ngInject*/
export function exampleService() {
// AngularJS will instantiate a singleton by calling "new" on this function
}
export default angular.module('sisaApp.example', [])
.service('example', exampleService)
.name;
:
$http
让我们说我想在这里使用yo angular-fullstack:route myroute
。我是否将它作为参数传递给函数?
除此之外,我该如何将此服务注入控制器?
如果我运行'use strict';
const angular = require('angular');
const uiRouter = require('angular-ui-router');
import routes from './myroute.routes';
export class MyrouteComponent {
/*@ngInject*/
constructor() {
this.message = 'Hello';
}
}
export default angular.module('sisaApp.myroute', [uiRouter])
.config(routes)
.component('myroute', {
template: require('./myroute.html'),
controller: MyrouteComponent,
controllerAs: 'myrouteCtrl'
})
.name;
并生成以下控制器文件:
var BASE_REF: FIRDatabaseReference {
return _BASE_REF
}
var storageRef : FIRStorageReference {
return FIRStorage.storage().reference()
}
func SignUp(username: String, email: String, password: String, data: NSData) {
FIRAuth.auth()?.createUserWithEmail(email, password: password, completion: { (user, error) in
if let error = error {
print(error.localizedDescription)
return
}
let changeRequest = user?.profileChangeRequest()
changeRequest?.displayName = username
changeRequest?.commitChangesWithCompletion({ (error) in
if let error = error {
print(error.localizedDescription)
return
}
})
let filePath = "profileImage/\(user!.uid)"
let metadata = FIRStorageMetadata()
metadata.contentType = "image/jpeg"
self.storageRef.child(filePath).putData(data, metadata: metadata, completion: { (metadata, error) in
if let error = error {
print("\(error.description)")
return
}
self.fileUrl = (metadata?.downloadURLs! [0].absoluteString)!
let changeRequestPhoto = user!.profileChangeRequest()
changeRequestPhoto.photoURL = NSURL(string: self.fileUrl)
changeRequestPhoto.commitChangesWithCompletion({ (error) in
if let error = error {
print(error.localizedDescription)
return
}else{
print("profile updated")
}
})
let appDelegate: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.login()
})
})
}
通过将它作为参数传递给构造函数来实现它,似乎并没有为我工作。
任何帮助将不胜感激! 提前谢谢!