Argument 'indexController' is not a function, got undefined

后端 未结 1 820
不思量自难忘°
不思量自难忘° 2021-01-24 09:30

This has been asked before but it didn\'t answer my question. I am pretty new to angular and I am just putting things together at the moment. I am trying to get my factory to wo

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-24 09:39

    You shouldn't recreate the angular module myApp again inside FactoryService, when you create myApp module again it flushes out old registered component to that module. So when you register FactoryService it removes out old register component, here it removes indexController controller. And when ng-controller directive gets evaluated it searches for indexController controller inside module and throws an error

    It should be

    angular.module('myApp')
        .factory('Contact', function ContactFactory(){
    

    instead of

    angular.module('myApp',[])
        .factory('Contact', function ContactFactory(){
    

    0 讨论(0)
提交回复
热议问题