gpt4 book ai didi

angularjs - Uncaught Error : [$injector:modulerr]

转载 作者:行者123 更新时间:2023-12-03 08:03:15 27 4
gpt4 key购买 nike

原谅我。我看过很多同名的话题,但对我没有帮助。可能每个人都有特定的代码。

    var app = angular.module('iop', []);
// Set up the service factory to create our Items interface to the

var obj={name:'sasha'}
var obj2= {status: 'run'}

app.factory('dataService', function(){
return{

text: ' js-frame?',
author: 'Vani'
}
})

app.controller('QuestionController',['obj','$scope','obj2','dataService'
function QuestionController(object,$scopes,object2,dataService){

$scopes.data= object.name

$scopes.text= object2.status +dataService.text

}]
)


<div ng-controller = "QuestionController">
Status :<p> {{data}}</p>
app: <p>{{text}}</p>
</div>

错误:未捕获的语法错误:意外的标记函数 index.html:46 Uncaught Error :[$injector:modulerr]

最佳答案

这两个变量:

var obj={name:'sasha'}
var obj2= {status: 'run'}

应该是模块值:

app.value("name", "sasha");
app.value("status", "run");

然后它们可以像这样注入(inject)到你的 Controller 中:

 app.controller('QuestionController',['name','$scope','status','dataService',
function QuestionController(name,$scope,status,dataService){

还有这一行:

 app.controller('QuestionController',['obj','$scope','obj2','dataService'
function QuestionController(object,$scope,object2,dataService){

dataService 之后缺少逗号

app.controller('QuestionController',['obj','$scope','obj2','dataService',
function QuestionController(object,$scope,object2,dataService){

您还多次拼错了 $scope。 (有$scopes)

希望这些更正会有所帮助。

关于angularjs - Uncaught Error : [$injector:modulerr],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25102206/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com