Skip to content

Instantly share code, notes, and snippets.

@mdmunir
Created May 22, 2017 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdmunir/1872e971ba6d9b371f5551166303f1be to your computer and use it in GitHub Desktop.
Save mdmunir/1872e971ba6d9b371f5551166303f1be to your computer and use it in GitHub Desktop.
Yii2 Angualjs Route
<?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>
<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>
<i page-title="Not Found"></i>
<h1>Page Not Found</h1>
test.directive('pageTitle', function () {
return {
restrict: 'A',
scope: {
pageTitle: '@'
},
link: function (scope) {
jQuery('title').text(scope.pageTitle);
}
};
});
<i page-title="View {{id}}"></i>
<?= date('i:s')?> View {{id}}. Back to <a href=".">main</a>&nbsp;
<a ng-if="id > 1" ng-href="view/{{id-1}}">&lt;&lt;</a>
&nbsp;
<a ng-if="id < 4" ng-href="view/{{id+1}}">&gt;&gt;</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