forked from pi-engine/pi
-
Notifications
You must be signed in to change notification settings - Fork 0
Dev.front js angular
nothing edited this page Mar 5, 2014
·
14 revisions
- phtml value assign to ng html template
//phtml
angular
.module('<?php echo $module; ?>', ['ngRoute', 'pi'])
.constant('config', {
//Translate ng template
t: {
key1: <?php echo _a('value1'); ?>
},
//phtml data assign to module config
data: {
list: <?php echo json_encode($list); ?>
}
});
//{{module}}/asset/admin/{{controller}}.js
angular.module('{{module}}')
.controller('PrivacyCtrl', ['$scope', 'config',
angular.extend($scope, config.data);
]);
//{{module}}/public/ng-template/admin/{{controller-action.html}}
<tr ng-repeat="item in list">
<td>{{item.title}}
<td>{{item.description}}
- Load data through ajax
//php multiple
IndexAction() {
return array(
'list' => array()
'key1' => 'value1',
...
)
}
//Only list
IndexAction() {
$list = array();
return array_values($list);
}
//Route
.when('/index', {
templateUrl: tpl('index-index'),
controller: 'PrivacyCtrl',
resolve: {
data: ['$q', '$rootScope', 'server',
function($q, $rootScope, server) {
var deferred = $q.defer();
//Loading
$rootScope.alert = 2;
//Ajax request data
server.getData().success(function(data) {
//Assign responsive data to controller
deferred.resolve(data);
//Clear loading message
$rootScope.alert = '';
});
return deferred.promise;
}]
}
})
.factory('name', ['$http',
function($http) {
// The public API of the service
var service = {
update: function() {
},
disable: function() {
},
remove: function() {
},
new: function() {
}
}
return service;
}
])
//Controller
.controller('PrivacyCtrl', ['$scope', 'server', 'data',
function($scope, server, data) {
angular.extend($scope, data);
}
]);
//{{module}}/asset/ng-template/admin/{{controller-action.html}}
<tr ng-repeat="item in list">
<td>{{item.title}}
<td>{{item.description}}