Thursday, May 11, 2017

How to use ngRoute in AngularJS Portlet

- Liferay 6.x, Liferay 7.0
- AngularJS 1.6.x

In this example, we will continue from the angularJS portlet created in earlier post.
1. create 2 new jsp for the routing example in the same folder with view.jsp
- first.jsp, with the following content.

<h2>This is the first page.</h2>

- second.jsp, with the following content

<h2>This is the second page.</h2>

2. in view.jsp, import angular-route.min.js

<script src="">

3. in view.jsp, create the _contextPath variable

    var _contextPath = '${pageContext.request.contextPath}';

4. in view.jsp, add the page routing controller.

<div ng-app="RoutingApp">
    <h2>AngularJS Routing Example</h2>
    <p>Jump to the <a href="#/first">first</a> or <a href="#/second">second page</a></p>
    <div ng-view></div>

5. in main.jsp, add the ngRoute to angular module

var myApp = angular.module('RoutingApp', ['ngRoute']);

6. in main.jsp, add the routing configuration

myApp.config( ['$routeProvider', function($routeProvider) {
        .when('/first', {
            templateUrl: _contextPath + '/first.jsp'
        .when('/second', {
            templateUrl: _contextPath + '/second.jsp'
            redirectTo: '/'

p/s: the _contextPath variable is important in Liferay environment to reach the pages inside portlet folder.


1 comment:

  1. Sportsbooks will sometimes shift the moneyline by quantity of} factors on both facet of those spread bets. Parlays are very interesting to bettors end result of|as a end result of} they pay out far more than the entire winnings of their constituent straight bets. However, it's far more troublesome to hit on a parlay than it's on a single wager. Moneyline bets don't have a variety or handicap, and require the chosen group to win the game outright. The favored group pays decrease odds than does the underdog; thus, it acts 온라인카지노 mainly as an enticement to take the underdog for a greater payout. Sometimes a bettor could couple this type of|this type of|this type of} guess on the favored group to extend the payout of a parlay.



Related Posts Plugin for WordPress, Blogger...