我尝试在 2 个按钮上设置路线时收到此错误。请帮助我找到出现此错误的原因,因为一切看起来都已就位并已定义。路线正在运行,但我没有在表中获取任何数据。我有:<html ng-app="myApp">
在主 htlm 中,模块没有在任何地方重新定义。我检查了其他类似的帖子,但没有找到任何可以解决我的问题的内容。
谢谢。
主要 html 文件片段:
//main controller mainCtrl.js:
angular.module("myApp", [])
.controller('myAppCtrl',['getStockData','corsService','$scope', function(getStockData ,corsService, $scope) {
corsService.enableCors();
getStockData.getData().then(function(data){
$scope.products = data;
console.log("hello from ctrl",data);
});
}])
.controller('salesCtrl', function(getSalesData, $scope){
getSalesData.getData().then(function(data){
$scope.salesData = data;
console.log(data);
})
})
var app = angular.module("myApp");
//------------------------------------------------------------------------------
//route provider: routeProvider.js:
angular.module("myApp", ["ngRoute"])
.config(function ($routeProvider) {
$routeProvider.when("/products", {
templateUrl: "views/productsView.html",
// controller:"myAppCtrl"
})
.when("/sales", {
templateUrl: "views/salesView.html",
})
.otherwise({
templateUrl: "views/productsView.html",
// controller: "myAppCtrl"
});
})
.controller("routeCtrl" ,function ($scope, $location){
$scope.setRoute=function(route){ …
Run Code Online (Sandbox Code Playgroud)