deesoft/yii2-angularjs

Yii2 widgets for angularjs

Installs: 85

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 1

Open Issues: 0

Type:yii2-extension

dev-master / 1.x-dev 2017-06-05 05:58 UTC

This package is not auto-updated.

Last update: 2024-11-09 00:25:19 UTC


README

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require deesoft/yii2-angularjs "~1.0"

or add

"deesoft/yii2-angularjs": "~1.0"

to the require section of your composer.json file.

Usage

Module Widget

file index.php

<div ng-app="angularYii">
    <?php Module::begin([
        'name' => 'angularYii', // module name, use for ng-app
        'controllers' => [
            'MainController' => [
                'sourceFile' => 'controllers/main-controller.js',
            ]
        ]
    ])?>
        <div ng-controller="MainController">
            <ul>
                <li ng-repeat="todo in todos">{{todo.name}}</li>
            </ul>
            <input ng-model="newValue"><button ng-click="addTodo()">Add</button>
        </div>
    <?php Module::end()?>
</div>

file controllers/main-controller.js

function($scope){
    $scope.todos = [
        {name: 'Satu'},
        {name: 'Dua'},
        {name: 'Tiga'},
    ];

    $scope.addTodo = function(){
        $scope.todos.push({
            name:$scope.newValue,
        });
        $scope.newValue = '';
    }
}

NgRoute widget

NgRoute widget is special widget of Module. It has property routes

file index.php

<div ng-app="ngrouteYii">
    <?= NgRoute::widget([
        'name' => 'ngrouteYii',
        'routes' => [
            '/' => [
                'templateFile' => 'templates/main.php',
                'controllerFile' => 'controllers/main.js',
            ],
            '/view/:id' => [
                'templateFile' => 'templates/view.php',
                'controllerFile' => 'controllers/view.js',
            ],
            '/edit/:id' => [
                'templateFile' => 'templates/edit.php',
                'controllerFile' => 'controllers/edit.js',
            ],
            '*' => [ // otherwise
                'templateFile' => 'templates/not-found.php',
            ],
        ]
    ])?>
</div>