I have written a simple Angular-js app as below:
angular.module("myApp",['ngRoute'])
.config(['$routeProvider',function($routeProvider){
$routeProvider
.when('/',{
name:'route1',
controller:'Route1Ctrl',
template:'partials/route1.tpl.html'
})
.otherwise({redirectTo:'/'});
}])
.controller('Route1Ctrl',['$scope',function($scope){
}});
The app fails to load and the only error message that I can see in the chrome console box is:
Uncaught objet
What can I do to get more usable error messages ?
instead of template: you must use templateUrl
Related
I am new on AngularJS. I am working on a project from a Udemy course.
When I add this code on my app.js:
weatherApp.config(function($routeProvider){
$routeProvider
.when('/', {
templateUrl: 'pages/home.htm',
controller: 'homeController'
})
.when('/forecast', {
templateUrl: 'pages/forecast.htm',
controller: 'forecastController'
})
});
i get this error on the browser console:
Error: [$compile:tpload]
Even if I download the code from the course link i get the same error. Any ideas why happen this?
Your browser is hindering your home.htm from running scripts that makes ajax call to another origin when opened via file path. There are countless resources explaining the same-origin policy.
If you serve your home.htm file with e.g. http-server you can navigate to the default url and port: 0.0.0.0:8080/home.htm. Note that you might also have to add the --cors flag found in the docs.
I am using interceptor for checking responses, and if there is error I am rejecting the response, which is working fine, but issue is after rejecting response I am getting html file which is not rendering properly, even in html response (from browser console), it is showing html tags but it is not rendering that and displaying blank page.
Any help would be highly appreciated.
I am using route provider for switching, where I am hitting to json and getting response.
$routeProvider
.when("/news", {
templateUrl: "newsView.html",
controller: "newsController",
resolve: {
message: $http.post('xyz.json',{});
}
}
})
Now my json contains error message, like below:
{data:{errorCode:'231',message:'Custom Error'}}
After this I have created one interceptor which check if there is error message then it rejects the response else it returns the response.
if(data.errorCode)
{
add error code to the custom directive message list
$q.reject(response)
}
return response
In my html file I have a custom directive.
<div message></div>
Now issue is that I am getting json file with error code and it is getting required data, and after that I am getting html file news.html file which is not rendering the custom directive and if I remove the reject , it is showing custom directive
angular version: 1.4.9
Hello,
I am packaging an angular web app written in John Papa code style. However I have been facing problems with basic things. One of these things is setting up routeProvider. I would like to configure it in the controller file, but seems to not work. When I configure it directly in the module config it does not accept controllerAs as syntax...
On mycontroller.js file
// Has no effect
angular.module('myDearModule').
controller('MyController', MyControllerFn).
config(function($routeProvider) {
$routeProvider.when('/page', {
templateUrl: 'tpl.html',
controller: 'MyController',
controllerAs: 'mycontrollerVm'
});
});
function MyControllerFn() {
....
Now, if I try it after loading everything, in a kind of module.routing.js file
// After setting up module and controller
angular.module('myDearModule').
config(function($routeProvider) {
$routeProvider.when('/page', {
templateUrl: 'tpl.html',
controller: 'MyController',
controllerAs: 'mycontrollerVm'
});
});
No effect... I also get this error: [ng:areq] Argument 'MyController' is not a function. Got undefined
I have tried to switch between views with this recommendation: Using angular $routeProvider with packaged apps
The directive and routing works fine but with no controller setted up :(
The same error happens when I use the ngController syntax inside the view.
I need to use routing to keep this web working. Am I doing something wrong or just there is no way? Could someone show me an example with controllerAs within a chrome app ? I have found only simple examples (no routing or page changing at all).
'MyController' is not a function. Got undefined
Could mean that you have a syntax error in your controller. There should be no error messages loading controllers, filters, etc. If you find any errors, and correct it, controllerAs should work as expected.
I used adal-angular js to protect my routes.
$routeProvider.
when("/dashboard", { templateUrl: "Views/Dashboard.html", controller: "DashboardController", requireADLogin: true })
But when Adal getting token, I have an error in console:
Error: [$compile:tpload] Failed to load template: Views/Dashboard.html (HTTP status: undefined undefined)
Could someone know why it happens?
First, forgive my english.
For me only have worked when I specified "/myUrl" in anonymousEndpoints. That skip the interceptor for this backend url.
I had an issue with this for angular ui bootstrap templates. Adding the path "uib/" to the anonymous endpoints array fixed my problem.
I'am trying to use a basic sample of interceptors, so I stared with a little piece of code but without success:
var app = angular.module('app',[]).
config(['$routeProvider','$locationProvider', function($routeProvider,$location) {
$routeProvider.
when('/home', {templateUrl: 'home.html', controller: homeCtrl}).
when('/login', {templateUrl: 'login.html', controller: loginController}).
otherwise({redirectTo : '/home' });
}]);
app.config(function ($httpProvider) {
$httpProvider.interceptors.push('httpRequestInterceptor');
});
When I launch my index page I have an error message in the console :
Uncaught TypeError: Cannot call method 'push' of undefined from app
Any idea?
Thanks
Your code is perfect. You need to make sure you are using the correct version of angularjs. The $http.interceptors array was added in version 1.1.4.
I made a plunker with your example working with angular 1.1.4, check it out here http://plnkr.co/edit/cuPfat?p=preview
$httpProvider.interceptors array was added in AngularJS v.1.1.4 (I believe). You're most probably using some older version of AngularJS.
Btw, that error says $httpProvider.interceptors is not defined, not $httpProvider as your title implies.