Created
May 22, 2017 09:07
-
-
Save mdmunir/1872e971ba6d9b371f5551166303f1be to your computer and use it in GitHub Desktop.
Yii2 Angualjs Route
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use yii\web\View; | |
use dee\angularjs\NgRoute; | |
//use yii\helpers\Html; | |
/* @var $this View */ | |
?> | |
<div ng-app="test"> | |
<?= | |
NgRoute::widget([ | |
'name' => 'test', | |
'html5Mode' => true, | |
'baseUrl' => 'test/', | |
'preJsFile' => 'js/pre.js', | |
'routes' => [ | |
'/' => [ | |
'templateFile' => 'templates/main.php', | |
], | |
'/view/:id' => [ | |
'templateFile' => 'templates/view.php', | |
], | |
'*' => [ | |
'templateFile' => 'templates/not-found.php', | |
], | |
], | |
]) | |
?> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<i page-title="Main"></i> | |
<ul> | |
<li ng-repeat="item in items"><a ng-href="view/{{item.id}}">{{item.value}}</a></li> | |
</ul> | |
<script> | |
function ($scope) { | |
$scope.items = [ | |
{id: 1, value: 'Satu'}, | |
{id: 2, value: 'Dua'}, | |
{id: 3, value: 'Tiga'}, | |
{id: 4, value: 'Empat'}, | |
]; | |
} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<i page-title="Not Found"></i> | |
<h1>Page Not Found</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test.directive('pageTitle', function () { | |
return { | |
restrict: 'A', | |
scope: { | |
pageTitle: '@' | |
}, | |
link: function (scope) { | |
jQuery('title').text(scope.pageTitle); | |
} | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<i page-title="View {{id}}"></i> | |
<?= date('i:s')?> View {{id}}. Back to <a href=".">main</a> | |
<a ng-if="id > 1" ng-href="view/{{id-1}}"><<</a> | |
| |
<a ng-if="id < 4" ng-href="view/{{id+1}}">>></a> | |
Path = {{ $location.path() }} | |
<script> | |
function ($scope, $routeParams, $location) { | |
$scope.id = parseInt($routeParams.id, 10); | |
$scope.$location = $location; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment