首页 > AngularJS自定义服务并依赖注入到自定义controller中失败,系统报错如下。

AngularJS自定义服务并依赖注入到自定义controller中失败,系统报错如下。

报错:

angularjs:

var app = angular.module('MyApp', []);
 app.controller('testA', ['$scope', 'remoteData' , function($scope, remoteData){
     console.log ('come in controller');
     $scope.getData = function(){
         console.log('name:' + remoteData.name + '  value:' + remoteData.value);
     }
 }]);

 app.factory('remoteData', function(){
     var data = {name:'n', value:'v'};                                     
     return data;
 })

HTML:



<div ng-app='MyApp'> <div ng-controller="testA"> <button ng-click="getData()">sdd</button> </div> </div>

是我参数名配置的问题,确实代码没问题,谢谢回答的两位。


这个应该没问题,你看下版本


我按照你的代码运行了一遍,是可以的,可以看这里:你的代码,没有错误。。。

【热门文章】
【热门文章】