gpt4 book ai didi

javascript - 在 Angular 工厂方法中不起作用

转载 作者:行者123 更新时间:2023-12-02 14:30:55 25 4
gpt4 key购买 nike

我知道这是一个愚蠢的问题。但不知道我的 Angular 工厂停止在我的页面上工作。以前整个脚本是一个文件,当时它正在工作,后来我将它分成不同的文件,然后它停止工作

这是我的文件。

app.js

'use strict';

angular.module('confusionApp', []);

Controller .js

'use strict';

angular.module('confusionApp')

.controller('MenuController', ['$scope','menuFactory', function($scope,menuFactory) {

$scope.tab = 1;
$scope.filtText = '';
$scope.showDetails = false;

$scope.dishes=menuFactory.getDishes();

$scope.select = function(setTab) {
$scope.tab = setTab;

if (setTab === 2) {
$scope.filtText = "appetizer";
}
else if (setTab === 3) {
$scope.filtText = "mains";
}
else if (setTab === 4) {
$scope.filtText = "dessert";
}
else {
$scope.filtText = "";
}
};

$scope.isSelected = function (checkTab) {
return ($scope.tab === checkTab);
};

$scope.toggleDetails = function() {
$scope.showDetails = !$scope.showDetails;
};
}])

.controller('ContactController', ['$scope', function($scope) {

$scope.feedback = {mychannel:"", firstName:"", lastName:"", agree:false, email:"" };

var channels = [{value:"tel", label:"Tel."}, {value:"Email",label:"Email"}];

$scope.channels = channels;
$scope.invalidChannelSelection = false;

}])

.controller('FeedbackController', ['$scope', function($scope) {

$scope.sendFeedback = function() {

console.log($scope.feedback);

if ($scope.feedback.agree && ($scope.feedback.mychannel == "")) {
$scope.invalidChannelSelection = true;
console.log('incorrect');
}
else {
$scope.invalidChannelSelection = false;
$scope.feedback = {mychannel:"", firstName:"", lastName:"", agree:false, email:"" };
$scope.feedback.mychannel="";
$scope.feedbackForm.$setPristine();
console.log($scope.feedback);
}
};
}])

.controller('DishDetailController', ['$scope','menuFactory', function($scope,menuFactory) {

$scope.dish= menuFactory.getDish(3);

}])

.controller('DishCommentController', ['$scope', function($scope) {

//Step 1: Create a JavaScript object to hold the comment from the form
var stars=[{value:"1"
},
{
value:"2"
},
{
value:"3"
},
{
value:"4"
},
{
value:"5"

}

];

$scope.isSelected=function(checkStar){
console.log(checkStar==5);
return checkStar==5;
};

$scope.stars=stars;

$scope.comment={name:"",rating:"5",textComments:"",date:""};

$scope.submitComment = function () {

$scope.comment.date=new Date().toISOString();

}
}])

;

service.js

'use strict';

angular.module('confusionApp'){
.factory('menuFactory',function(){

var dishes=[
{
name:'Uthapizza',
image: 'images/uthapizza.png',
category: 'mains',
label:'Hot',
price:'4.99',
description:'A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer.',
comments: [
{
rating:5,
comment:"Imagine all the eatables, living in conFusion!",
author:"John Lemon",
date:"2012-10-16T17:57:28.556094Z"
},
{
rating:4,
comment:"Sends anyone to heaven, I wish I could get my mother-in-law to eat it!",
author:"Paul McVites",
date:"2014-09-05T17:57:28.556094Z"
},
{
rating:3,
comment:"Eat it, just eat it!",
author:"Michael Jaikishan",
date:"2015-02-13T17:57:28.556094Z"
},
{
rating:4,
comment:"Ultimate, Reaching for the stars!",
author:"Ringo Starry",
date:"2013-12-02T17:57:28.556094Z"
},
{
rating:2,
comment:"It's your birthday, we're gonna party!",
author:"25 Cent",
date:"2011-12-02T17:57:28.556094Z"
} ]
},
{
name:'Zucchipakoda',
image: 'images/zucchipakoda.png',
category: 'appetizer',
label:'',
price:'1.99',
description:'Deep fried Zucchini coated with mildly spiced Chickpea flour batter accompanied with a sweet-tangy tamarind sauce',
comments: [
{
rating:5,
comment:"Imagine all the eatables, living in conFusion!",
author:"John Lemon",
date:"2012-10-16T17:57:28.556094Z"
},
{
rating:4,
comment:"Sends anyone to heaven, I wish I could get my mother-in-law to eat it!",
author:"Paul McVites",
date:"2014-09-05T17:57:28.556094Z"
},
{
rating:3,
comment:"Eat it, just eat it!",
author:"Michael Jaikishan",
date:"2015-02-13T17:57:28.556094Z"
},
{
rating:4,
comment:"Ultimate, Reaching for the stars!",
author:"Ringo Starry",
date:"2013-12-02T17:57:28.556094Z"
},
{
rating:2,
comment:"It's your birthday, we're gonna party!",
author:"25 Cent",
date:"2011-12-02T17:57:28.556094Z"
} ]
},
{
name:'Vadonut',
image: 'images/vadonut.png',
category: 'appetizer',
label:'New',
price:'1.99',
description:'A quintessential ConFusion experience, is it a vada or is it a donut?',
comments: [
{
rating:5,
comment:"Imagine all the eatables, living in conFusion!",
author:"John Lemon",
date:"2012-10-16T17:57:28.556094Z"
},
{
rating:4,
comment:"Sends anyone to heaven, I wish I could get my mother-in-law to eat it!",
author:"Paul McVites",
date:"2014-09-05T17:57:28.556094Z"
},
{
rating:3,
comment:"Eat it, just eat it!",
author:"Michael Jaikishan",
date:"2015-02-13T17:57:28.556094Z"
},
{
rating:4,
comment:"Ultimate, Reaching for the stars!",
author:"Ringo Starry",
date:"2013-12-02T17:57:28.556094Z"
},
{
rating:2,
comment:"It's your birthday, we're gonna party!",
author:"25 Cent",
date:"2011-12-02T17:57:28.556094Z"
}
]
},
{
name:'ElaiCheese Cake',
image: 'images/elaicheesecake.png',
category: 'dessert',
label:'',
price:'2.99',
description:'A delectable, semi-sweet New York Style Cheese Cake, with Graham cracker crust and spiced with Indian cardamoms',
comments: [
{
rating:5,
comment:"Imagine all the eatables, living in conFusion!",
author:"John Lemon",
date:"2012-10-16T17:57:28.556094Z"
},
{
rating:4,
comment:"Sends anyone to heaven, I wish I could get my mother-in-law to eat it!",
author:"Paul McVites",
date:"2014-09-05T17:57:28.556094Z"
},
{
rating:3,
comment:"Eat it, just eat it!",
author:"Michael Jaikishan",
date:"2015-02-13T17:57:28.556094Z"
},
{
rating:4,
comment:"Ultimate, Reaching for the stars!",
author:"Ringo Starry",
date:"2013-12-02T17:57:28.556094Z"
},
{
rating:2,
comment:"It's your birthday, we're gonna party!",
author:"25 Cent",
date:"2011-12-02T17:57:28.556094Z"
} ]
}
];
var menufac = {};
menufac.getDishes = function(){
return dishes;
};
menufac.getDish = function (index) {
return dishes[index];
};
return menufac;
}
);

这是我的排列顺序

<script src="../app/scripts/app.js"></script>
<script src="../app/scripts/controller.js"></script>
<script src="../app/scripts/service.js"></script>

我知道它一点也不难,但我无法弄清楚

最佳答案

第三行有一个多余的大括号,可能会导致编译错误。也许这是你的错误。如果没有,请编辑您的问题。

'use strict';

angular.module('confusionApp'){
.factory('menuFactory',function(){
...

关于javascript - 在 Angular 工厂方法中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37842030/

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