AngularJS Note
==========================================================
TABLE EXAMPLE:
列管編號 |
公文號 |
主旨 |
承辦科室 |
送辦日期 |
結案日期 |
{{case.caseID|| “–” }} | {{case.fromID || “–“}} | {{case.title | limitTo: 20 || “–“}}{{case.title.length > 20 ? ‘…’ : ”}} | {{case.unitName|| “–“}} | {{case.dateStart|| “–“}} | {{case.dateEnd|| “–“}} |
==========================================================
HOW TO LIMIT DATA WHICH IS TOO LONG:
{{case.title | limitTo: 20 || “–“}}{{case.title.length > 20 ? ‘…’ : ”}}
==========================================================
GET RECORDS ORDERED:
case in caseSet | orderBy:predicate:reverse
ng-click=”predicate = ‘caseID’; reverse=!reverse”
==========================================================
GET ALL KEY NAMES AND BY INDEX(EASY FOR COMPARE):
var keysbyindex = Object.keys($scope.oldCaseSet[0]);for (var i = 0; i < keysbyindex.length; i++) {
alert($scope.oldCaseSet[0][keysbyindex[i]]);//331199
}
==========================================================
THE WAY TO COUNT KEYS OR PROPERTIES OF CERTAIN OBJECT:
Object.keys($scope.oldCaseSet[0]).length;
==========================================================
EMIT/ON EXAMPLE:
module.controller('MainCtrl',
function ($scope, $http) {
$scope.setInfo = function () {
$scope.$emit('setCurrentCategory', $scope.currentCategory);
$scope.$emit('showFunction', 'null');
};
});
module.controller('functionCtrl',
function ($scope, $http) {
$scope.$on('setCurrentCategory', function (e, setCurrentCategory) {
$scope.Category = setCurrentCategory;
});
==========================================================
HOW TO PASS ATTRIBUTE SUCH AS ID FROM ITEM IN NG-REPEAT :
$scope.linkToNews = function (newsID) {
alert(newsID);
//window.open(“” + newsID);
}
==========================================================
REMEMBER TO ADD [] AS THE SECOND PARAMETER OF ANGULAL.MODULE!
==========================================================
HOW TO ADD DEFAULT SELECTION:(FIND ANOTHER WAY IN WILL’S BLOG)
$http.post(“ajax_event.aspx/getAllRole”, “”)
.success(function (data) {
var roleSet = JSON.parse(data.d);
$scope.roleSet = roleSet;
$scope.roleSet.unshift({ Name: “請選擇” });
$scope.currentRole = roleSet[0];
});
==========================================================
HOW TO SEND SCOPE TO ANOTHER SCOPE:
CHILDREN SCOPE SENDING ARGS:
$scope.$emit(‘setCurrentCategory’, $scope.currentCategory);
PARENT SCOPE GETTING ARGS:
$scope.$on(‘setCurrentRole’, function (e, currentRole) {
$scope.Role = currentRole;
});
==========================================================
INITIALIZE MODULE:
var module = angular.module(“MainModule”, []);
==========================================================
INITIALIZE CONTOLLER:
function ($scope, $http)
{$http.post(“ajax_event.aspx/getAllCategory”, “”)
.success(function (data) {
var cateSet = JSON.parse(data.d);
$scope.categorySet = cateSet;
$scope.categorySet.unshift({ Name: “請選擇” });
$scope.currentCategory = $scope.categorySet[0];
});
});