在 angular js 中找不到未定义的视图,模块已定义
Can't find view of undefined in angular js, module is defined
我正在尝试向 github 上的 Hygieia 项目添加一个小部件。当我将小部件添加到页面时,它不显示并且出现此错误:
TypeError: Cannot read property 'view' of undefined
at link (http://localhost:3000/app/dashboard/directives/widget.js:49:64)
at http://localhost:3000/bower_components/bower.js:9682:44
at invokeLinkFn (http://localhost:3000/bower_components/bower.js:9688:9)
at nodeLinkFn (http://localhost:3000/bower_components/bower.js:9198:11)
at delayedNodeLinkFn (http://localhost:3000/bower_components/bower.js:9446:11)
at compositeLinkFn (http://localhost:3000/bower_components/bower.js:8547:13)
at compositeLinkFn (http://localhost:3000/bower_components/bower.js:8550:13)
at compositeLinkFn (http://localhost:3000/bower_components/bower.js:8550:13)
at compositeLinkFn (http://localhost:3000/bower_components/bower.js:8550:13)
at compositeLinkFn (http://localhost:3000/bower_components/bower.js:8550:13) <widget name="aws-status" class="ng-isolate-scope">
我已经在类似模块已经存在的代码之后对我添加的所有代码进行了建模,但由于某种原因,该小部件不会显示在页面上。这是我声明模块的地方,如果您需要查看任何其他代码部分以确定我做错了什么,请告诉我:
(function () {
'use strict';
var widget_state,
config = {
view: {
defaults: {
title: 'AWS Status' // widget title
},
controller: 'awsStatusViewController',
controllerAs: 'ctrl',
templateUrl: 'components/widgets/awsstatus/view.html'
},
config: {
controller: 'awsStatusConfigController',
controllerAs: 'ctrl',
templateUrl: 'components/widgets/awsstatus/config.html'
},
getState: getState
};
angular
.module(HygieiaConfig.module)
.config(register);
register.$inject = ['widgetManagerProvider', 'WidgetState'];
function register(widgetManagerProvider, WidgetState) {
widget_state = WidgetState;
widgetManagerProvider.register('aws-status', config);
}
function getState(widgetConfig) {
return HygieiaConfig.local ?
widget_state.READY :
(widgetConfig.id ? widget_state.READY : widget_state.CONFIGURE);
}
});
我发现我的文件末尾缺少 2 个括号。没有这些,代码似乎从未执行过。
正确的代码如下所示:
(function () {
'use strict';
var widget_state,
config = {
view: {
defaults: {
title: 'AWS Status' // widget title
},
controller: 'awsStatusViewController',
controllerAs: 'ctrl',
templateUrl: 'components/widgets/awsstatus/view.html'
},
config: {
controller: 'awsStatusConfigController',
controllerAs: 'ctrl',
templateUrl: 'components/widgets/awsstatus/config.html'
},
getState: getState
};
angular
.module(HygieiaConfig.module)
.config(register);
register.$inject = ['widgetManagerProvider', 'WidgetState'];
function register(widgetManagerProvider, WidgetState) {
widget_state = WidgetState;
widgetManagerProvider.register('aws-status', config);
}
function getState(widgetConfig) {
return HygieiaConfig.local ?
widget_state.READY :
(widgetConfig.id ? widget_state.READY : widget_state.CONFIGURE);
}
})();
我正在尝试向 github 上的 Hygieia 项目添加一个小部件。当我将小部件添加到页面时,它不显示并且出现此错误:
TypeError: Cannot read property 'view' of undefined
at link (http://localhost:3000/app/dashboard/directives/widget.js:49:64)
at http://localhost:3000/bower_components/bower.js:9682:44
at invokeLinkFn (http://localhost:3000/bower_components/bower.js:9688:9)
at nodeLinkFn (http://localhost:3000/bower_components/bower.js:9198:11)
at delayedNodeLinkFn (http://localhost:3000/bower_components/bower.js:9446:11)
at compositeLinkFn (http://localhost:3000/bower_components/bower.js:8547:13)
at compositeLinkFn (http://localhost:3000/bower_components/bower.js:8550:13)
at compositeLinkFn (http://localhost:3000/bower_components/bower.js:8550:13)
at compositeLinkFn (http://localhost:3000/bower_components/bower.js:8550:13)
at compositeLinkFn (http://localhost:3000/bower_components/bower.js:8550:13) <widget name="aws-status" class="ng-isolate-scope">
我已经在类似模块已经存在的代码之后对我添加的所有代码进行了建模,但由于某种原因,该小部件不会显示在页面上。这是我声明模块的地方,如果您需要查看任何其他代码部分以确定我做错了什么,请告诉我:
(function () {
'use strict';
var widget_state,
config = {
view: {
defaults: {
title: 'AWS Status' // widget title
},
controller: 'awsStatusViewController',
controllerAs: 'ctrl',
templateUrl: 'components/widgets/awsstatus/view.html'
},
config: {
controller: 'awsStatusConfigController',
controllerAs: 'ctrl',
templateUrl: 'components/widgets/awsstatus/config.html'
},
getState: getState
};
angular
.module(HygieiaConfig.module)
.config(register);
register.$inject = ['widgetManagerProvider', 'WidgetState'];
function register(widgetManagerProvider, WidgetState) {
widget_state = WidgetState;
widgetManagerProvider.register('aws-status', config);
}
function getState(widgetConfig) {
return HygieiaConfig.local ?
widget_state.READY :
(widgetConfig.id ? widget_state.READY : widget_state.CONFIGURE);
}
});
我发现我的文件末尾缺少 2 个括号。没有这些,代码似乎从未执行过。
正确的代码如下所示:
(function () {
'use strict';
var widget_state,
config = {
view: {
defaults: {
title: 'AWS Status' // widget title
},
controller: 'awsStatusViewController',
controllerAs: 'ctrl',
templateUrl: 'components/widgets/awsstatus/view.html'
},
config: {
controller: 'awsStatusConfigController',
controllerAs: 'ctrl',
templateUrl: 'components/widgets/awsstatus/config.html'
},
getState: getState
};
angular
.module(HygieiaConfig.module)
.config(register);
register.$inject = ['widgetManagerProvider', 'WidgetState'];
function register(widgetManagerProvider, WidgetState) {
widget_state = WidgetState;
widgetManagerProvider.register('aws-status', config);
}
function getState(widgetConfig) {
return HygieiaConfig.local ?
widget_state.READY :
(widgetConfig.id ? widget_state.READY : widget_state.CONFIGURE);
}
})();