Javascript AngularJS 1.X ES6继承问题

Javascript AngularJS 1.X ES6继承问题,javascript,angularjs,ecmascript-6,Javascript,Angularjs,Ecmascript 6,尝试访问子控制器中的父属性时遇到问题。 我正在使用ES6语法,并尝试使用extends语法 ConversationDetailController(子级) ConversationListController(父级) 我做错什么了吗?因为日志为我显示了子范围中的this.conversations的空数组[]。在此之后,我还有一个错误: angular.js:12722 TypeError: Cannot read property 'id' of undefined at Conversat

尝试访问子控制器中的父属性时遇到问题。 我正在使用ES6语法,并尝试使用extends语法

ConversationDetailController(子级)

ConversationListController(父级)

我做错什么了吗?因为日志为我显示了子范围中的
this.conversations
的空数组
[]
。在此之后,我还有一个错误:

angular.js:12722 TypeError: Cannot read property 'id' of undefined
at ConversationDetailController.activate (http://localhost:3000/app/index.module.js:602:34)
at ConversationDetailController.ConversationListController (http://localhost:3000/app/index.module.js:504:11)
at new ConversationDetailController (http://localhost:3000/app/index.module.js:582:95)
at invoke (http://localhost:3000/bower_components/angular/angular.js:4535:17)
at Object.instantiate (http://localhost:3000/bower_components/angular/angular.js:4543:27)
at http://localhost:3000/bower_components/angular/angular.js:9395:28
at http://localhost:3000/bower_components/angular-ui-router/release/angular-ui-router.js:4081:28
at invokeLinkFn (http://localhost:3000/bower_components/angular/angular.js:9039:9)
at nodeLinkFn (http://localhost:3000/bower_components/angular/angular.js:8533:11)
at compositeLinkFn (http://localhost:3000/bower_components/angular/angular.js:7929:13) <div ui-view="" layout="column" class="w-100 ng-scope">
angular.js:12722 TypeError:无法读取未定义的属性“id”
在ConversationDetailController.activate上(http://localhost:3000/app/index.module.js:602:34)
位于ConversationDetailController.ConversationListController(http://localhost:3000/app/index.module.js:504:11)
在新的ConversationDetailController上(http://localhost:3000/app/index.module.js:582:95)
在调用时(http://localhost:3000/bower_components/angular/angular.js:4535:17)
在Object.instantiate(http://localhost:3000/bower_components/angular/angular.js:4543:27)
在http://localhost:3000/bower_components/angular/angular.js:9395:28
在http://localhost:3000/bower_components/angular-ui-router/release/angular-ui-router.js:4081:28
在肯德基(http://localhost:3000/bower_components/angular/angular.js:9039:9)
在诺德琳(http://localhost:3000/bower_components/angular/angular.js:8533:11)
在KFN(http://localhost:3000/bower_components/angular/angular.js:7929:13) 
谢谢, 加布里埃尔

调用父构造函数。给你

this.activate();
let id = this.$stateParams.id;
由于
this
ConversationDetailController
的实例,因此调用它的
activate
方法,而不是
ConversationListController
的方法。你就这样

this.activate();
let id = this.$stateParams.id;
但是,
$stateParams
尚未设置,因为:

super($rootScope, $state, $log); <- You are here
...
this.$stateParams = $stateParams;

super($rootScope,$state,$log);我怎么能这么做,你举个例子吗?但如果这样做,我可以在我的子控制器中修改来自父控制器的数据吗?就像删除会话列表中的会话一样?事实上,我一开始以为有一个vm调用另一个vm,而不是继承。有两个不同的独立视图吗?它不是独立视图,但子视图是在父视图的
中调用的。好的,我明白了,我不会在控制器之间使用继承,每个控制器都有它负责的视图的一部分。所以,当你使用state.go时,我会输入参数,
{id:…,conversations:…}
或者你需要的任何东西。是的,我也有这个想法。但是如果我在更新
DetailController
中的对话列表时在
$state.go
方法中使用params,它将不会在
ListController
中更新它。对吗?好的,如果我理解你说的话,
super()
方法调用的是我的子控制器的
activate
方法,而不是父控制器。你有什么办法避免这种情况吗?在
activateChild
中重命名
activate
!非常感谢:D
super($rootScope, $state, $log); <- You are here
...
this.$stateParams = $stateParams;