[AngularJS] Solution for Main page not display

Background : Angularjs application (angularjs version 1.3.15)
Problem : main page display nothing

Demo code (with a small small error but serious):

In app.js

angular.module('myApp', [
  'ngCookies',
  'ngResource',
  'ngSanitize',
  'ngRoute'
])
  .config(function($routeProvider) {
    $routeProvider
      .when('/', {
        templateUrl: 'views/main.html',
        controller: 'MainCtrl'
      })
      .otherwise({
        redirectTo: '/'
      });
  });

In main.js

console.log('Before main controller');
var app = angular.module('myApp', []);
app.controller('MainCtrl', function ($scope) {
    console.log('In main controller');
});
console.log('After main controller');

In my console, it displays only :

Before main controller
After main controller

What’s wrong ??
Continue reading

Advertisements

[AngularJS] solution for jsonp not working

I got to try a http jsonp call an external url in AngularJS :

$http.jsonp('http://localhost/myJsonfile?callback=JSON_CALLBACK')
    .success(function(data){
       console.log('success');
    })
    .error(function () {
      console.log('error')
    });

Using jsonp and adding the “callback=JSON_CALLBACK” to the end of the url allows me to call an external url.
NB. Calling an external url by $http.get will return an “Cross-Origin Request Blocked” error.

My json file in /var/www is like this (only for test):

[{"id": "1"},
 {"id": "2"},
 {"id": "3"}
]

But the call always return an error 😦
Continue reading