gpt4 book ai didi

javascript - console.log 在 Angular Controller 中不起作用

转载 作者:数据小太阳 更新时间:2023-10-29 05:38:25 24 4
gpt4 key购买 nike

嗨,我一直在尝试进入 angular.j。我尝试了以下代码。但是 console.log() 似乎不起作用。有什么遗漏吗??比如 Angular 概念之类的?

var foodshareModule= angular.module('food',['ui.router','ngResource']);

console.log("Main file getting included");


foodshareModule.controller("personController", function($scope) {
console.log($scope);
$scope.firstName = "John";
$scope.lastName = "Doe";
console.log($scope.firstName);
console.log($scope.lastName);
});

foodshareModule.controller('scratchListController', function($scope,$state,Notes){

console.log("working");

$scope.scratchpad =Food.query();

$scope.deleteScratch = function (scratch,flag) {
if(flag === 0) { //Checks if Bulk delete or single delete
if(confirm("You Clicked DELETE !! Are you sure ?")) {
scratch.$delete(function() { //Single delete
window.location.href = 'http://localhost:1337';
});
}
}
else { //Bulk delete
scratch.$delete(function() {
window.location.href = 'http://localhost:1337';
});
}

}

$scope.emptyScratchpad = function () {
var ask = false;
if (confirm ("You are about Empty Scratchpad. Sure ????")) {
ask = true;
}
if(ask === true) {
for (var i = 0; i < $scope.scratchpad.length; i++) {
$scope.deleteScratch($scope.scratchpad[i],1);
}
}

}
})



foodshareModule.factory('Food', function($resource) {
return $resource('http://localhost:1337/Food:id', { id: '@_id' }, {
update: {
method: 'PUT'
}
});
});

如有任何帮助,我们将不胜感激。提前致谢。

最佳答案

通过查看你的代码,你似乎在 scratchListController 中注入(inject)了错误的依赖项,它应该是 Food 而不是 Notes

代码

foodshareModule.controller('scratchListController', function($scope, $state, Food) { //you were added Notes, but there should be Food
console.log("working");
//..other code here
})

关于javascript - console.log 在 Angular Controller 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29321698/

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