无法使用typescript访问angular中另一个控制器中声明的$rootscope属性
unable to access $rootscope property declared in one controller in other in angular using typescript
我在如下所示的ts文件中声明了一个rootscope自定义属性
module MyApp.Entity{
export interface IRootScope extends ng.IRootScopeService {
userData: any;
clientData: any;
}
}
在我的一个服务文件中,我分配了值
export class Service1 {
constructor(private apiService: MyApp.Common.Services.apiService, private notificationService: MyApp.Common.Services.notificationService,
private $base64: JQueryBase64Static, private $cookieStore: ng.cookies.ICookieStoreService, private $rootScope: MyApp.Entity.IRootScope) {
}
saveData(){
this.$rootScope.clientData = clientData; // Data got assigned
}
}
现在在其他控制器文件中,我试图访问这个根范围属性
class controller2{
Clients: any;
constructor(private service1: MyApp.Service.Service1, private $rootScope: MyApp.Entity.IRootScope){
this.Clients = this.$rootScope.clientData; // clientData is Undefined i.e here //it is creating new rootscope again I guess ..so How to access a single global //rootscope
}
}
您使用的是this.$rootScope
,它是$rootScope的另一个实例,因为它只在当前作用域中定义,如果您删除this.
,它应该可以在中工作
相关文章:
- 如何声明具有相同控制器的处于相同状态的多个模板
- 当指令中已经给定作用域时,如何访问控制器中声明的函数
- 无法使用typescript访问angular中另一个控制器中声明的$rootscope属性
- 为什么要将控制器声明为自身中的变量或使用$scope
- 如何在 PopConconfirm 中单击按钮 yes 时调用在 Angular 控制器中声明的删除函数
- AngularJS 在 1 个应用程序中声明多个控制器
- 构建现实世界的AngularJS应用程序,我应该如何在html中声明我的控制器.我需要在索引中声明所有.html吗?
- 在控制器中声明的变量,带有“var”,但在控制器中引用为范围
- 如何在控制器中声明$rootscope并在另一个控制器中访问它
- 列出 AngularJS 模块中声明的指令/控制器
- 使用 Angular 常量声明控制器名称
- 在 angularjs 控制器范围内声明函数和属性,但不附加到$scope
- Marionette控制器功能声明-最佳实践
- 控制器声明中的Angular Meteor箭头函数
- 在单个模块中声明时未定义控制器
- 在AngularJS中声明控制器
- 在配置中声明的路由与由其控制器声明的路由相比
- 如何将应用程序控制器中声明的值传递给组件
- 在我的应用程序中声明和链接控制器时遇到麻烦
- 你必须在视图中声明控制器吗?或者你可以在$routeProvider中声明它吗