Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMuhammad Fitri
5,018 PointsNodeJS Application permanent link
In Node the page is produce dynamicly without sending new HTTP request so the link of the current page is the same as the as the app link. How to produce specific link for the different element in the MEAN app?
Example. I setup my MEAN application on the domain www.example.com. The app display few products. When I click one of the product the app simply updating the page with information of specific product using two way data binding without requesting new page thus the domain directory will stay at www.example.com. This will cause a problem if I want to track or show the product to a friends since there's no specific link to the product. Others problem include SEO and some others stuff.
Thanks.
1 Answer
Jesus Mendoza
23,289 PointsIn your root page '/' you send a few products with JSON, no big deal because your root page in Angular is the same as '/' in Node right? Now let's say you click a button that sends you to the full product catalog view.
So, when you click an element you can set a $http request in your controller
<a href="#products" ng-click="getProducts()">Products</a>
$scope.getProducts = function() {
$http({
method: 'GET',
url: '/products' // Here you place the URL where you want to get the products from.
})
.success(function(data) { // Pass data to the view })
.error(function() { //Handle the error });
}
or give the products view a single controller.
$scope.products = {};
$http({
method: 'GET',
url: '/products';
})
.success(function(data) { $scope.products = data; })
.error(function() { // Handle the error });
I don't know much about AngularJS but I hope you get the idea. If you are using UI-Router you can resolve it from the UI-Router state config too.