Angular structure de base
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script>
<script type="text/ng-template" id="fiches.html">
<h1> fiches </h1>
</script>
<script type="text/ng-template" id="details.html">
<h1> details </h1>
</script>
<div data-ng-controller="ficheController as vm">
<a href="#/fiches"> to fiches </a> <br/>
<a href="#/details"> to details fiches </a> <br/>
<data-ng-view> chargement .. </data-ng-view>
</div>
JavaScript
"use strict";
(function() {
var app = angular.module('myApp', ['ngRoute']);
app.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/fiches', {
templateUrl: 'fiches.html',
controller: 'ficheController'
}).
when('/details', {
templateUrl: 'details.html',
controller: 'ficheDetailsController'
}).
otherwise({
redirectTo: '/fiche'
});
}]);
// controler
var ficheController = function () {
var mc = this;
mc.fiches = [];
mc.key = 0;
};
//ficheController.$inject = ['$routeParams']
// controler
var ficheDetailsController = function () {
var mc = this;
};
// controller pour gérer les fiches
app.controller("ficheController",ficheController);
// controller pour gérer les détails des fiches
app.controller("ficheDetailsController",ficheDetailsController);
// déclarer la route
})();