Angularjs: Error: [ng:areq] Argument 'HomeController' is not a function, got undefined

前端 未结 24 1605
抹茶落季
抹茶落季 2020-11-27 12:22

This is my demo using angularjs, for creating a service file, and adding service to a controller.

I have two problems with my demo:

  • One is when I put <
24条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 12:42

    In my case, I was missing the name of the Angular application in the html file. For example, I had included this file to be start of my application code. I had assumed it was being ran, but it wasn't.

    app.module.js

    (function () {
        'use strict';
    
        angular
            .module('app', [
            // Other dependencies here...
            ])
        ;
    
    })();
    

    However, when I declared the app in the html I had this:

    index.html

    
    

    But to reference the Angular application by the name I used, I had to use:

    index.html (Fixed)

    
    

提交回复
热议问题