python , angular js 学习记录【1】
1.日期格式化
Letter | Date or Time Component | Presentation | Examples |
---|---|---|---|
G |
Era designator | Text | AD |
y |
Year | Year | 1996 ; 96 |
M |
Month in year | Month | July ; Jul ; 07 |
w |
Week in year | Number | 27 |
W |
Week in month | Number | 2 |
D |
Day in year | Number | 189 |
d |
Day in month | Number | 10 |
F |
Day of week in month | Number | 2 |
E |
Day in week | Text | Tuesday ; Tue |
a |
Am/pm marker | Text | PM |
H |
Hour in day (0-23) | Number | 0 |
k |
Hour in day (1-24) | Number | 24 |
K |
Hour in am/pm (0-11) | Number | 0 |
h |
Hour in am/pm (1-12) | Number | 12 |
m |
Minute in hour | Number | 30 |
s |
Second in minute | Number | 55 |
S |
Millisecond | Number | 978 |
z |
Time zone | General time zone | Pacific Standard Time ; PST ; GMT-08:00 |
Z |
Time zone | RFC 822 time zone | -0800 |
2.scope之间通信(angular js)
父scope定义一个方法(假设controller为ParentCtrl)
$scope.$on('change-breadcrumb', function(event,data) { $scope.breadcrumb = Util.breadcrumb("h"+$routeParams.id,data); });
子scope触发父scope的方法(假设controller为ChildCtrl)
$scope.$emit('change-breadcrumb',newValue);
此时可以执行父scope里面的方法,要注意的是在页面中的两个controller的位置
<div ng-controller="ParentCtrl"> <!--父级--> <div ng-controller="ChildCtrl"></div> <!--子级--> </div>
页面弹出框dialog不属于上面的页面布局,使用方法为
dialog.context_scope.$emit('change-breadcrumb',newValue);
更多细节请参见AngularJS的学习--$on、$emit和$broadcast的使用 - 疯狂的原始人
3.$.grep angular.forEach
$.grep() 方法是按照某种条件来过滤数组
nums = $.grep(nums, function (num, index) { // num = 数组元素的当前值 // index = 当前值的下标 return isNaN(num); });
angular.forEach方法用来循环数组
angular.forEach($scope.templates, function (t) { if ($scope.pool.template.id == t.id) { $scope.pool.template = t; } })
两者都有循环数组的功能,在angular js 中尽量用后者进行循环
4.使用session
angular.module('cvirt.login', ['ngCookies']) .controller('loginController', loginController) .controller('logoutController', logoutController);
在controller中声明session,并设置值即可
$cookieStore.put('token', escape(data.token));
$cookieStore.put('username', $scope.username);
获取session中的值
$cookieStore.get('username')