Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJs. Routing. Handle server request. Few questions
    text
    copied!<p>I have following page:</p> <pre><code>&lt;!doctype html&gt; &lt;html lang="en" ng-app="myModule"&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"&gt;&lt;/script&gt; &lt;script&gt; var myModule = angular.module('somename', []); myModule.config(function ($routeProvider) { $routeProvider. when('/zzz', {templateUrl:'' , controller: TestCtrl}). when('/test1', {template:' ', controller: TestDataCtrl}). when('/test2', {template:'/abc ', controller: function TestCtrl1() {alert("test2")} }). when('/test/:userid', { controller: TestDataCtrl }). when('/users/:userid', {templateUrl: '/users/:userid?html=true', controller: UserDataCtrl}). otherwise({redirectTo: '/works'}); }); function TestCtrl($scope) { alert("test") } function UserDataCtrl($scope, $http) { ... } function TestDataCtrl($scope, $http, $routeParams, $route) { $http.get('users/1').success(function (data) { console.log("UserDataCtrl"); $scope.user = data; }); } &lt;/script&gt; &lt;/head&gt; &lt;body ng-app="myModule"&gt; &lt;div ng-view&gt;&lt;/div&gt; {{1+1}} &lt;/body&gt; &lt;/html&gt; </code></pre> <p>1)When I navigate to the following url <code>http://localhost:7000/service/1#/test1</code> it is allways sends two requests to server (in my case REST service), something like <code>http://localhost:7000/service/1</code> and <code>http://localhost:7000/archivarius/users/1</code>. Can I somehow handle first (useless) browser request, maybe using AngularJs controller? I mean when user enter url <code>http://localhost:7000/service/1#/test1</code> the only things (requests) should happen in test2 controller. Is it possible?</p> <p>2)In routing configuration why do I have to specify either template or templateUrl? Why I can't just specify only controller for route?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload