bennadel / angularjs-routing Goto Github PK
View Code? Open in Web Editor NEWAn example of how to do deep routing in an AngularJS application when ngView is not enough.
License: Other
An example of how to do deep routing in an AngularJS application when ngView is not enough.
License: Other
Both basic routing example and the one which include html on page without reloading generates the error given below in Google Chrome, code and error are given below...Guide me with solution for same...
index.html
html ng-app="demoApp"
head
meta charset="UTF-8"
titleRoutingtitle
script src="../angular.min.js"script
script src="../angular-route.js"script
script src="app.js"script
head
body
div ng-viewdiv
body
html
app.js
var demoApp = angular.module('demoApp', ['ngRoute']);
demoApp.controller('NameCtrl', function($scope, $http){
$http.get("../countries.json").success(function(data){
alert("Hello");
$scope.countries = data;
}).error(function(data, status){
alert("No Hello");
alert(status);
$scope.data = data || "Request failed";
$scope.status = status;
});
});
demoApp.controller('CntryDtlCtrl', function($scope, $routeParams){
alert($routeParams);
console.log($routeParams);
});
demoApp.config(function($routeProvider){
$routeProvider
.when('/',{
template: '<ul><li ng-repeat="entity in countries">{{entity.country}}</li></ul>',
controller: 'NameCtrl'
}).
when('/:country',{
// Add # with a name i.e country name in the url to get this content eg. file:///Users/karthicklove/Documents/Aptana%20Studio%203%20Workspace/Object_Javascript/Angular_Js/50_examples/Routing/index.html#/china
template: '<h1>TODO create country detail view<h1>',
controller: 'CntryDtlCtrl'
}).
otherwise({
redirectTo: '/'
});
});
Error: "XMLHttpRequest cannot load file://localhost/Users/karthicklove/Documents/Aptana%20Studio%203%20Workspace/Object_Javascript/Angular_Js/50_examples/countries.json. Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https, chrome-extension-resource. "
Hi Ben, In my opinion your approach is very flexible than using ng-view and the ui-Roure project. I upgrade angular to v1.2.0rc1 and unfortunately the ng-switch not work!. I remove ng-switch-when="standard" and the template loaded!! can you help me?
Ben, thanks for this. I spent hours with vanilla routing, and more hours with ui-router... nothing did the trick. Parent views getting re-rendered when only the child views should have been affected was the crux of the problem, which your implementation solved.
I ended up doing a bit of abstraction but am not yet sure if it was wise -- only time will tell!
A small note: as of Angular 1.2.0rc1, in the $routeChangeSuccess
callback, getting the action can be done like so:
var action = $route.current.$$route && $route.current.$$route.action;
App.config(function ($routeProvider) {
$routeProvider
.when('/', { templateUrl: 'Partials/View1.htm', controller: 'SimpleController' })
.when('/partial2', { templateUrl: 'Partials/View2.htm', controller: 'SimpleController' })
.otherwise({ redirectTo: '/AJTest' });
});
App.controller('SimpleController', function ($scope) {
$scope.customers =
[
{ name: 'a', city: 'a' },
{ name: 'b', city: 'b' },
{ name: 'c', city: 'c' },
{ name: 'd', city: 'd' }
];
$scope.addCustomer = function () {
$scope.customers.push({ name: $scope.newCustomer.name, city: $scope.newCustomer.city });
}
});
</script>
<div data-ng-controller="SimpleController">
Name :<br />
<input type="text" data-ng-model="name" /> {{ name }}
<ul>
<li data-ng-repeat="cust in customers | filter:name | orderBy:city">{{ cust.name + ' ' + cust.city}} </li>
</ul>
</div>
</body>
Please help. thanks in advance.
So you've probably been following this thread: angular/angular.js#1198 and known there's a lot of suggestions and discussions around nested routing (including your own solution).
I was looking over your code because I was asked to give a recommendation and unfortunately there are some parts to every solution I've found which have remained unclear.
That being said, I think it would be awesome if we can get everyone's efforts merged together and have been thinking of starting a Nested Routes team on the AngularUI org.
Would you be interested? It would likely be built off a foundation of your code mixed with a few other solutions to come up with the best of all worlds.
How to remove #
ie
http://localhost/AngularJS/#/home ==>> http://localhost/AngularJS/home
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.