2
這是app.states.js:AngularJS:HomeController中沒有顯示出來
angular.module('fuelComparatorApp', ['ui.router'])
.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise('/404');
$urlRouterProvider.when('', '/');
$stateProvider
.state('home', {
url: '/',
templateUrl: 'app/components/home/views/home.view.html',
controller: "homeController",
controllerAs: 'ctrl'
})
.state('404', {
url: '/404',
templateUrl: 'app/shared/404.html'
});
}]);
這是home.services.js:
(function() {
'use strict';
angular.module('fuelComparatorApp.homeServices', []).service('sayHelloService', sayHelloService);
sayHelloService.$inject = ['$http', '$q'];
function sayHelloService() {
function sayHi() {
console.log("hi from home service");
}
}
})();
home.controller。 js
(function() {
'use strict';
angular.module('fuelComparatorApp').controller('homeController', homeController);
homeController.$inject = ["$scope", "$http", "$window", "$q", "sayHelloService"];
function homeController($scope, $http, $window, $q, sayHelloService) {
const vm = this;
vm.fuelComparatorService = sayHelloService;
sayHelloService;
return vm;
}
})();
在index.html中有通常的ng-app="fuelComparatorApp"
和使用ng-controller="homeController"
指令的home.view.html。
沒有錯誤,只是index.html沒有顯示home.view.html中的任何內容,就好像我在某處丟失了某些東西。
你可以在jsfiddler中粘貼 –
@MDGosoddin我對JSFiddle不太好,但是這裏有:https://jsfiddle.net/makdeniss/xfL80ora/#&togetherjs=HDaeCnk8fN –