I have create a new project, but got a problem which I am not able to fix.
Here's my example:
angular.module('MosysTimes', ['ngRoute']).config($routeProvider, RouteConfiguration);
function RouteConfiguration ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'start.html',
controller: 'WelcomeController'
})
.when('/login', {
templateUrl: 'login.html',
controller: 'LoginController'
})
.otherwise({
redirectTo: '/'
});
}
It always says:
$routeProvider is undefined....
Any help will be appreciated ?
You should change your code to this.
angular.module('MosysTimes', ['ngRoute']).config(['$routeProvider',function($routeProvider)
{
$routeProvider
.when('/', {
templateUrl: 'start.html',
controller: 'WelcomeController'
})
.when('/login', {
templateUrl: 'login.html',
controller: 'LoginController'
})
.otherwise({
redirectTo: '/'
});
}]);
Did you add ngroute script to you index html?
for example:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.min.js"></script>
and try to use following syntax
angular.module("MosysTimes",['ngRoute']).config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'start.html',
controller: 'WelcomeController'
})
.when('/login', {
templateUrl: 'login.html',
controller: 'LoginController'
})
.otherwise({
redirectTo: '/'
});
});
angular.module('yourModule').config(['$routeProvider', function($routeProvider){
$routeProvider
.when() .....
}]);
You should declare $routeProvider into function. After that you can use this $routeProvider to access the loading template on your main page.
thanx to you all, after trying your hints I got it working and a bit of more understanding angular.. thx...
Related
It does not work with the specified templateUrl: test.html but works if you specify the template: 'Hello '
WORK
app.config(function($routeProvider){
$routeProvider
.when('/test', {
template: '<h1>home</h1>',
controller: 'ctrl'
})
// .otherwise({
// redirectTo: '/home',
// controller: 'ProductCtrl'
// });
});
DO NOT WORK
app.config(function($routeProvider){
$routeProvider
.when('/test', {
templateUrl: 'test.html',
controller: 'ctrl'
})
// .otherwise({
// redirectTo: '/home',
// controller: 'ProductCtrl'
// });
});
and I have a sign ! in the path to the file that is #!/test
LINK
<a style="color:white;" href="#!/test">Go</a>
I'm using nw.js
You could try to put a path to your template url
.when('/test', {
templateUrl: './test.html',
controller: 'ctrl'
})
my code its something like this:
app.config(function ($routeProvider) {
$routeProvider
.when('/', {
controller: 'HomeController',
templateUrl: 'views/home.html'
})
.when('/login', {
controller: 'LoginController',
templateUrl: 'views/login.html'
})
.otherwise({
redirectTo: '/'
});
});
But I wonder if it could be something like this:
...
.when('/login' OR '/' OR '/SOMETHING', {
controller: 'LoginController',
templateUrl: 'views/login.html'
})
...
I already read doc of when function and a have see this question too, but unfortunately I have not be able to find a conclusive answer.
Can when function of routeProvider take multiple url paths?
Thank you in advance.
Your code seems to be fine.Can you just guide me which error you are getting?
In order to reuse the data you can simply:
app.config(function ($routeProvider) {
loginData = {
controller: 'LoginController',
templateUrl: 'views/login.html'
};
$routeProvider
.when('/', loginData)
.when('/login', loginData)
…
.otherwise({
redirectTo: '/'
});
});
Change the below url
http://example.com/#/alphabits/a b c
to
http://example.com/#!/alphabits/a_b_c
Any suggestion
You can change this from $locationProvider. I used this code in my application to change this.
angular.module('myApp').config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$locationProvider.hashPrefix(''); // We are actually removing ! from URLs as ! is default one.
$routeProvider
.when('/', {
templateUrl: 'templates/home.tpl.html',
controller: 'homeCtrl'
})
.when('/about', {
templateUrl: 'templates/about.tpl.html',
controller: 'aboutCtrl'
})
.otherwise({
redirectTo: '/'
});
}]);
I'm trying to replace AngularJS Route with UI Router since that seems to be what everyone uses. I'm just getting started and am wondering how to replace the following code with $stateProvider:
$routeProvider
.when('/login', {
templateUrl: 'views/login.html',
controller: 'LoginCtrl'
})
.when('/dashboard', {
templateUrl: 'views/dashboard.html',
controller: 'DashboardCtrl'
})
.otherwise({
redirectTo: '/login'
});
Replace when with state:
$stateProvider
.state('state1', {
url: "/state1",
templateUrl: "partials/state1.html"
})
More details here: https://github.com/angular-ui/ui-router
I try to declare a route to use angular,in my security.yml after authentication i well be redirect to #/welcome but consider it a comment
default_target_path: #/welcome
my app.js
routeApp.config(['$routeProvider',function($routeProvider) {
// Routing system
$routeProvider
.when('/login', {
templateUrl: Routing.generate('login'),
controller: 'SecurityController'
})
.when('/welcome', {
templateUrl: Routing.generate('ard_backend_test'),
controller: 'WelcomeController'
})
.otherwise({
redirectTo: '/login'
});
}]);
Just add a double quote for your string and the hash # character will be able to escape.
default_target_path: "#/welcome"
Update: Do not define the default client route in your yml configuration.
This should be part of your angular router configuration. Depending which router you are using of course.
Here is an example with angular's default routeService:
angular.module('MyApp', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/welcome', {
templateUrl: 'partials/welcome.tpl.html',
controller: 'WelcomeCtrl'
}).
when('/some-other-route', {
templateUrl: 'partials/some-other-route.tpl.html',
controller: 'SomeOtherCtrl'
}).
otherwise({
redirectTo: '/welcome'
});
}]);