无法在角度js中找到未定义的视图,定义了模块

时间:2016-07-22 15:28:41

标签: angularjs gulp hygieia

我正在尝试将小部件添加到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);
    }
});

1 个答案:

答案 0 :(得分:0)

我发现在文件末尾我遗漏了两个括号。如果没有这些,似乎代码永远不会执行。

正确的代码如下所示:

(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);
    }
})();