本文介绍了Angular JS Provider无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 请在下面的代码中说明什么错误.., 它对我不起作用 Please suggest whats wrong in below code..,its not working for me app.provider('MyProvider', function () { var Name = 'Default'; this.MyProviderMethod = function (s) { Name = s; }; function Greeter(a) { this.greet = function () { return Name + ',' + a; } }; this.$get = function (a) { return new Greeter(a); }; }); app.config(function (MyProviderProvider) { MyProviderProvider.MyProviderMethod('Hi'); }); //app.controller('ControllerforProvider', ['MyProvider', function (MyProvider) { // // this.DisplayName = MyProvider.greet('anvi'); // this.DisplayName = "fsss"; //}]); app.controller('ControllerforProvider', ['MyProvider', function (MyProvider) { // this.DisplayName = MyProvider.greet('anvi'); this.DisplayName = "h"; }]); 控制器中 in controller<div ng-controller="ControllerforProvider as Contr"> {{ Contr.DisplayName }} </div> 推荐答案 get = function(a){ return new Greeter(a); }; }); app.config(函数(MyProviderProvider){ MyProviderProvider.MyProviderMethod(' 嗨'); }); // app.controller('ControllerforProvider',['MyProvider',function(MyProvider) ){ // // this.DisplayName = MyProvider.greet('anvi') ; // this.DisplayName =fsss; // }]); app.controller(' ControllerforProvider',[' MyProvider',函数(MyProvider){ // this.DisplayName = MyProvider.greet('anvi'); this .DisplayName = H; }]); get = function (a) { return new Greeter(a); }; }); app.config(function (MyProviderProvider) { MyProviderProvider.MyProviderMethod('Hi'); }); //app.controller('ControllerforProvider', ['MyProvider', function (MyProvider) { // // this.DisplayName = MyProvider.greet('anvi'); // this.DisplayName = "fsss"; //}]); app.controller('ControllerforProvider', ['MyProvider', function (MyProvider) { // this.DisplayName = MyProvider.greet('anvi'); this.DisplayName = "h"; }]); 控制器中 in controller<div ng-controller="ControllerforProvider as Contr"> {{ Contr.DisplayName }} </div> 您好, 您必须定义Hello,You have to define 范围请参阅此文章。 Angular Tutorial - 第1部分:Angular.js简介 [ ^ ] scope Please refer this Article.Angular Tutorial - Part 1: Introduction to Angular.js [^] 这篇关于Angular JS Provider无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-22 22:39