We got two routes and two controllers bind to each route. You can toggle between two routes: /english and /german. Both got different controllers, both got different templates.
1) If you click "First View" you will be taken to URL "#/english" where you got binded MainFirstCtrl to this HTML:
<div style="background: mediumpurple">{{ctrl.title}}</div>
2) If you click "First View" you will be taken to URL "#/english" where you got binded MainSecondCtrl to this HTML:
<div style="background: yellowgreen">{{ctrl.title}}</div>
3) Now using ui-sref you can change states:
<button type="button" ui-sref="first">Go to First View (/english)</button>
<button type="button" ui-sref="second">Go to Second View (/german)</button>
4) States are defined in ui-router config like this:
$stateProvider.state('first', {
url: '/first',
template: '<div style="background: mediumpurple">{{ctrl.title}}</div>',
controller: 'MainFirstCtrl',
controllerAs: 'ctrl'
});
Working example below:
var myapp = angular.module('myapp', ['ui.router']);
//Here are our routes defined
myapp.config(['$stateProvider', function ($stateProvider) {
$stateProvider.state('first', {
url: '/english',
template: '<div class="view" style="background: mediumpurple">{{ctrl.title}}</div>',
controller: 'MainFirstCtrl',
controllerAs: 'ctrl'
});
$stateProvider.state('second', {
url: '/german',
template: '<div class="view" style="background: yellowgreen">{{ctrl.title}}</div>',
controller: 'MainSecondCtrl',
controllerAs: 'ctrl'
});
}]);
//Here are our two different controllers that would control the same view BUT with different routes
myapp.controller('MainFirstCtrl', ['$scope', function($scope) {
this.title = 'This is english view';
}]);
myapp.controller('MainSecondCtrl', ['$scope', function($scope) {
this.title = 'This is german view';
}]);
button {
background: #1e6791;
border: 0;
color: #fff;
padding: 15px 20px;
font-family: arial;
font-size: 15px;
margin: 15px 0px;
box-shadow: 0px 0px 1px rgba(0,0,0,.3);
}
.view {
width:300px;
height:150px;
}
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.18/angular-ui-router.js"></script>
</head>
<body ng-app="myapp">
<button type="button" ui-sref="first">Go to First View (/english)</button>
<button type="button" ui-sref="second">Go to Second View (/german)</button>
<div ui-view></div>
<div show-contact></div>
</body>
</html>
var text1='hello worl'; $scope.myvar = $filter('translate')(text1);