Reputation: 1528
I don't seem to get angularjs running. Short description: All i'm trying to do here is to reach the orderservice thru the 3 steps. Route -> orderController -> orderService and there console.log() a message. This will later make a ajaxcall to server and retrive some data to play with.
Problem seem to occure when app.js is trying to call controller and nothing happens. No error, nada.
View loading JS
<script type="text/javascript" src="../../Scripts/angular.min.js"></script>
<script type="text/javascript" src="../../Scripts/angular-route.min.js"></script>
<script type="text/javascript" src="../../App_AngularJs/app.js"></script>
<script type="text/javascript" src="../../App_AngularJs/controllers/orders/orderController.js"></script>
<script type="text/javascript" src="../../App_AngularJs/service/orderService.js"></script>
<div class="container" ng-app="app">
</div>
app.js
console.log("app.js LOADED...");
angular.module('app', ['ngRoute', 'app.controller', 'app.service'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'partials/orderList.htm',
controller: 'MyCtrl1'
});
}
]);
orderController.js
console.log("orderController.js LOADED...");
angular.module('app.controller', [])
.controller('MyCtrl1', ['$scope', 'orderService', function ($scope, orderService) {
console.log("hej");
init();
function init() {
console.log("hej");
var hej = orderService.query();
console.log(hej);
}
}
]);
orderService
console.log("orderService.js LOADED...");
angular.module('app.service', [])
.service('orderService', [
function() {
return {
query: function() {
// the query code here.
}
};
}
]);
Structure
Upvotes: 1
Views: 3617
Reputation: 5857
you should have ng-view
in your html in order to work with $routeProvider add following code to html is one way to do it...
<ng-view></ng-view>
but if you want to work your example which is working (I tested it here is PLUNKER look console output...) just add ng-controller to one of your html tag like this
<div ng-controller="MyCtrl1"></div>
Upvotes: 2