使用以下代码可以判断是否开启了strict模式
var isStrict = (function () { return !this; })();
console.log(isStrict);
因为在strict模式下,上面函数里的this是undefined
而在非strict模式下,上面函数里的this是Window(如果在浏览器里运行)或者其他运行环境,比如node等
使用以下代码可以判断是否开启了strict模式
var isStrict = (function () { return !this; })();
console.log(isStrict);
因为在strict模式下,上面函数里的this是undefined
而在非strict模式下,上面函数里的this是Window(如果在浏览器里运行)或者其他运行环境,比如node等
有些时候我们需要directive生成api,可以在其他地方(controller)调用
下面介绍下简单的步骤:
html:
<div expose="exposedApi"></div>
js:
directive('expose',function(){
return {
restrict: "A",
scope: {
api: "=expose"
}
};
这个时候controller离的exposedApi变量和directive里的api是双向绑定的
directive('expose',function(){
return {
restrict: "A",
scope: {
api: "=expose"
},
controller: function($scope){
$scope.number = 0;
$scope.api={
count:function(){
$scope.number ++;
}
};
},
template: '<div class="well">' +
'<p>count: {{number}}</p>' +
'</div>'
};
controller("ctrl",function($scope){
$scope.count = function(){
$scope.exposedApi.count();
};
})
http://shengoo.github.io/angularjs-practice
<!DOCTYPE html>
<html ng-app="app">
<head lang="en">
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.css" />
<script src="../bower_components/angular/angular.js"></script>
</head>
<body ng-controller="ctrl">
<div class="container">
<div expose="exposedApi"></div>
<a ng-click="count()" class="btn btn-primary">click</a>
<div expose="exposedApi2"></div>
<a ng-click="count2()" class="btn btn-primary">click</a>
</div>
<script>
angular.module("app",[])
.controller("ctrl",function($scope){
$scope.count = function(){
$scope.exposedApi.count();
};
$scope.count2 = function(){
$scope.exposedApi2.count();
};
})
.directive('expose',function(){
return {
restrict: "A",
scope: {
api: "=expose"
},
controller: function($scope){
$scope.number = 0;
$scope.api={
count:function(){
$scope.number ++;
}
};
},
template: '<div class="well">' +
'<p>count: {{number}}</p>' +
'</div>'
};
})
</script>
</body>
</html>
网上有人给出了方案:
1)进入刚安装的Android Studio目录下的bin目录。找到idea.properties文件,用文本编辑器打开。
2)在idea.properties文件末尾添加一行: disable.android.first.run=true ,然后保存文件。
3)关闭Android Studio后重新启动,便可进入界面。
在AngularJS中,Dom操作应该在directive里进行,而不应该在controllers, services或者其他任何地方。
<my-widget>
可复用的HTML行为
<div ng-click="...">
包装一个jQuery插件
<div ui-date></div>
你需要和DOM交互的绝大多数情况
angular.module('MyDirectives',[]);
angular.module('app',['MyDirectives']);
angular.module('MyDirectives')
.directive('myDirective', function(){
// TODO:
});
<div my-directive>...</div>
attributes
<div my-directive></div>
element
<my-directive></my-directive
rarely used
‘C’: classes ‘M’ : comments
restrict: 'AE'
scope: {
someParam: '='
}
或者
scope: true
这个scope不会继承其他scope
scope参数是从HTML的属性(attribute)传进来的
scope: {
param1: '=', // 双向绑定(directive和controller)
param2: '@', // 单向绑定
param3: '&' // 单向行为
}
<div my-directive
param1="someVariable"
param2="My name is {{name}}"
param3="doSth()"
>
除了简单的不正确调用 $apply
或 $digest
,有些情况下,即使没有犯错,也有可能得到这个错误。
function MyController($scope, thirdPartyComponent) {
thirdPartyComponent.getData(function(someData) {
$scope.$apply(function() {
$scope.someData = someData;
});
});
}
function MyController($scope, thirdPartyComponent) {
thirdPartyComponent.getData(function(someData) {
$timeout(function() {
$scope.someData = someData;
}, 0);
});
}
windows: C:\Users\[YourName]\AppData\Roaming\Sublime Text 3\Packages
mac: /Library/Application\ Support/Sublime\ Text\ 3/Packages/
linux:
Package Control.last-run
Package Control.ca-list
Package Control.ca-bundle
Package Control.system-ca-bundle
Package Control.cache/
Package Control.ca-certs/
cd [package folder]/User/
git init
git add
git commit -m "Initial"
git remote add origin [your git repo]
git push origin master
cd [package folder]
mv User User.old
git clone [your git repo] User
cd [package folder]/User
git add -A
git commit -m "Update settings"
git push
cd [package folder]/User
git pull
“git add -A
” 相当于 “git add .; git add -u
“.
“git add .
“虽然看起来像是把目录下所有文件都添加,但是其实并没有,它只会添加新建和更改过的文件。
“git add -u
” 中-u代表的是update
,只会记录已有文件的update,不会记录新建的文件。
“git add -A
” 可以做上面两件事的.
你可以按照下面的命令去测试这些区别:
git init
echo Change me > change-me
echo Delete me > delete-me
git add change-me delete-me
git commit -m initial
echo OK >> change-me
rm delete-me
echo Add me > add-me
git status
# Changed but not updated:
# modified: change-me
# deleted: delete-me
# Untracked files:
# add-me
git add .
git status
# Changes to be committed:
# new file: add-me
# modified: change-me
# Changed but not updated:
# deleted: delete-me
git reset
git add -u
git status
# Changes to be committed:
# modified: change-me
# deleted: delete-me
# Untracked files:
# add-me
git reset
git add -A
git status
# Changes to be committed:
# new file: add-me
# modified: change-me
# deleted: delete-me
git add -A
?添加所有git add .
?添加新文件和修改的文件,?不包括删除的git add -u
?添加修改和和删除的文件,?不包括新增的
"use strict";
// make a common module
angular.module("common",[])
.filter("someFilter", function (){
return function (text) {
return text;
};
});
// use it
angular.module("app",["common"]);
angular.module("app", ["kendo.directives"])
.controller("news", function($scope,newsService) {
var dataSource = new kendo.data.DataSource({
transport: {
read: dataSourceRead
}
});
function dataSourceRead(options){
//todo: show loading
newsService.getByCategory($scope.selectedCategory.value)
.then(
function(response){
options.success(response);
//todo: hide loading
},
function(response){
options.error(response);
//todo: handle errors.
});
}
$scope.newsListViewOptions = {
dataSource: dataSource
};
})
.service('newsService', function($q, $http) {
this.getByCategory = function(category){
var url = "your url";
var request = $http({
method: "jsonp",
url: url
});
return( request.then( handleSuccess, handleError ) );
};
function handleError( response ) {
//if no message return from server
if (
! angular.isObject( response.data ) ||
! response.data.message
) {
return( $q.reject( "An unknown error occurred." ) );
}
return( $q.reject( response.data.message ) );
}
function handleSuccess( response ) {
return( response.data );
}
});
当Android的service被停止(内存不够、被其他app杀掉)的时候,加入以下代码到你的service里,就可以马上重新启动了。
@Override
public void onDestroy() {
super.onDestroy();
// Restart service in 500 ms
((AlarmManager) getSystemService(Context.ALARM_SERVICE))
.set(AlarmManager.RTC,
System.currentTimeMillis() + 500,
PendingIntent.getService(this, 3, new Intent(this, TaskService.class), 0));
}