2015年12月27日 星期日

heroku deploy


   git add .
   git commit -m "Demo"
   git push heroku master

   heroku open

2015年12月20日 星期日

query relation parse , leancloud





    success: function(user) {


// incorrect var relation = user[0].relation("RelationBuilding");

var relation = user[0].relation("RelationBuilding");
relation.query().find({
 success: function(list) {
  response.success(list);
 },
 error: function(error) {
  response.error(error);
 }
});
};

2015年12月16日 星期三

The view is not updated when the model updates in AngularJS



http://nathanleclaire.com/blog/2014/01/31/banging-your-head-against-an-angularjs-issue-try-this/

            $scope.building.name = $scope.buildingIndel.text[0].init;
            $scope.building.id = building.id;

$scope.$apply();

angularjs controller directive callback parameter


<body ng-app="myApp">

    <div ng-controller="testCtrl">
      <strong>Name: </strong>{{name}}<br>
        <a dirt-pass-fun callback="changename">
        </a>
    </div>

<script>
var myApp = angular.module('myApp',[]);

myApp.controller("testCtrl", function($scope) {
      this.nickname="ctrl1 nickname";
      $scope.name="ctrl1";
      $scope.modelOne = {
        foo: 'Pascal'
      };

    $scope.changename = function(t) {    
      $scope.name+=t;
    }

});
myApp.directive('dirtPassFun', function() {
  return {
      restrict: 'A',
      scope: {
          callback: '='
      },
      template: '<button ng-click="callback(\'i am man\')">Click</button>'
  };
});
</script>

</body>

2015年12月15日 星期二

ERROR: (gcloud.preview.app.deploy) unrecognized arguments: --promote


usage: gcloud preview app deploy  DEPLOYABLES [DEPLOYABLES ...] [optional flags]
ERROR: (gcloud.preview.app.deploy) unrecognized arguments: --promote





use:

gcloud preview app deploy app.yaml --promote --docker-build=remote

dont user:
gcloud preview app deploy app.yaml --promote

2015年12月1日 星期二

$http.post(uploadUrl, fd, {

})
.success(function(result1){

})

//////////////////////////////////////////////////////////////////////////////////////

 $http.get('/setuploadpath/'+buildingName)
.then(function(result2) {

            return $http.post("/upload", fd, {transformRequest: angular.identity,headers: {'Content-Type': undefined}});
})


//////////////////////////////////////////////////////////////////////////////////////

2者的 result ,

result2.data = result1

2015年11月27日 星期五

2015年11月26日 星期四

angularjs factory return problem null undefined




========== work =========

  factory.getInit = function(type,lable){
    var t=null;
    angular.forEach(factory.models[type], function(value, key) {
        if(value.lable == lable){
          t=value.init;
          console.log("getInit-value.init: "+t);
        }
    });
    return t;
  };

========== doesn't work =========


  factory.getInit = function(type,lable){
    angular.forEach(factory.models[type], function(value, key) {
        if(value.lable == lable){
          console.log("getInit-value.init: "+value.init);
          return value.init;
        }
    });
  };


2015年11月22日 星期日

2015年11月19日 星期四

angularjs date

https://docs.angularjs.org/api/ng/filter/date

<span ng-non-bindable>{{1288323623006 | date:'medium'}}</span>:
    <span>{{1288323623006 | date:'medium'}}</span><br>
<span ng-non-bindable>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span>:
   <span>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span><br>
<span ng-non-bindable>{{1288323623006 | date:'MM/dd/yyyy @ h:mma'}}</span>:
   <span>{{'1288323623006' | date:'MM/dd/yyyy @ h:mma'}}</span><br>
<span ng-non-bindable>{{1288323623006 | date:"MM/dd/yyyy 'at' h:mma"}}</span>:
   <span>{{'1288323623006' | date:"MM/dd/yyyy 'at' h:mma"}}</span><br>



{{1288323623006 | date:'medium'}}Oct 29, 2010 11:40:23 AM
{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}2010-10-29 11:40:23 +0800
{{1288323623006 | date:'MM/dd/yyyy @ h:mma'}}10/29/2010 @ 11:40AM
{{1288323623006 | date:"MM/dd/yyyy 'at' h:mma"}}10/29/2010 at 11:40AM

2015年11月18日 星期三

angularjs , log in redirect ng-router


http://stackoverflow.com/questions/11541695/redirecting-to-a-certain-route-based-on-condition


'use strict';

var app = angular.module('app', [])
    .config(['$routeProvider', function($routeProvider) {
        $routeProvider
            .when('/', {
                templateUrl: "login.html",
                controller: LoginController
            })
            .when('/private', {
                templateUrl: "private.html",
                controller: PrivateController,
                resolve: {
                    factory: checkRouting
                }
            })
            .when('/private/anotherpage', {
                templateUrl:"another-private.html",
                controller: AnotherPriveController,
                resolve: {
                    factory: checkRouting
                }
            })
            .otherwise({ redirectTo: '/' });
    }]);

var checkRouting= function ($q, $rootScope, $location) {
    if ($rootScope.userProfile) {
        return true;
    } else {
        var deferred = $q.defer();
        $http.post("/loadUserProfile", { userToken: "blah" })
            .success(function (response) {
                $rootScope.userProfile = response.userProfile;
                deferred.resolve(true);
            })
            .error(function () {
                deferred.reject();
                $location.path("/");
             });
        return deferred.promise;
    }
};
=========================


angular.module('yoApp')
  .service('appService', function ($q, $timeout, $rootScope, $location) {


this.isAdmin=function(){
console.log("isAdmin");

       var deferred = $q.defer();

      deferred.resolve(true);
       // deferred.reject();
       // $location.path("/about");

       return deferred.promise;
}
});



  .config(function ($routeProvider) {

    $routeProvider
      .when('/me', {
        template: '<h1> me </h1>',
        resolve: {
            factory: function(appService) {
              return appService.isAdmin();
            }
        }
      })


  });




2015年11月11日 星期三

angular js Dependency injection

https://www.airpair.com/angularjs/posts/top-10-mistakes-angularjs-developers-make


Dependency injection is one of AngularJS's best patterns. It makes testing much simpler

var app = angular.module('app',[]); app.controller('MainCtrl', function($scope, $timeout){ $timeout(function(){ console.log($scope); }, 1000); });
Here, it's very clear that MainCtrl depends on $scope and $timeout.



angularness factory vs service

http://ithelp.ithome.com.tw/question/10161278


Service 是用 new 來建立的


Factory 的行為很簡單,Controller 注入Factory 取得的物件就是被 factory object ({}) 包起來並且 return 的物件
也就是說,假如沒有被 { } 包起來值都不會被外面取得。
(p.s. 不一定要 return object, 任何 type 都可以)

Service 是把東西存在 this 裡面,像是我們平常在製作 constructor 一樣。
以上範例假如寫成 constructor 就會是

2015年11月9日 星期一

2015年11月8日 星期日

angularjs complied order ,structure


http://stackoverflow.com/questions/20663076/angularjs-app-run-documentation
















Here's the calling order:
  1. app.config()
  2. app.run()
  3. directive's compile functions (if they are found in the dom)
  4. app.controller()
  5. directive's link functions (again, if found)
Here's a simple demo where you can watch each one executing (and experiment if you'd like).
============
very good example:
============
index.html:54 app config
index.html:50 app run
index.html:37 directive setup
index.html:39 directive compile
index.html:58 app controller
index.html:45 directive link


        <script>
                var myApp = angular.module('myApp', []);
                myApp.factory('aProvider', function() {
                   console.log("factory");
                });

                myApp.directive("test1", function() {
                    console.log("directive setup");
                    return {
                        compile: function() {console.log("directive compile");}
                    }
                });

                myApp.directive("test2", function() {
                    return {
                        link: function() {console.log("directive link");}
                    }
                });

                myApp.run(function() {
                    console.log("app run");
                });

                myApp.config( function() {
                    console.log("app config");
                });

                myApp.controller('myCtrl', function($scope) {
                    console.log("app controller");
                });
        </script>

================



2015年10月27日 星期二

grunt





best tutorial, step by step:
http://fairwaytech.com/2014/01/understanding-grunt-part-1-installation-linting-concatenation-and-minification/


linting
making sure that our code adheres to good JavaScript practices

concat
整合檔案的任務

uglify
是用來設定壓縮檔案並根據專案的 metadata 產生一些註解。



watch
This can be run on the command line with grunt watch. When it detects any of the files specified have changed (here, I just use the same files I told JSHint to check), it will run the tasks you specify, in the order they appear.


● 外掛原則上可以分成兩類:開發過程的工具、發佈的工具
◎ 發佈的工具,以下將介紹:
  grunt-contrib-concat
  grunt-contrib-uglify
  grunt-contrib-cssmin
  grunt-contrib-copy
  grunt-usemin
◎ 開發過程的工具,以下將介紹:
  grunt-contrib-jshint
  grunt-contrib-connect
  grunt-contrib-watch

grunt 教學 tutorial

http://gruntjs.com/getting-started

http://clayliao.blogspot.tw/2013/06/introducing-grunt.html


example Gruntfile.js

module.exports = function(grunt) { // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { options: { banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' }, build: { src: 'src/<%= pkg.name %>.js', dest: 'build/<%= pkg.name %>.min.js' } } }); // Load the plugin that provides the "uglify" task. grunt.loadNpmTasks('grunt-contrib-uglify'); // Default task(s). grunt.registerTask('default', ['uglify']); };




package.js

{ "name": "my-project-name", "version": "0.1.0", "devDependencies": { "grunt": "~0.4.5", "grunt-contrib-jshint": "~0.10.0", "grunt-contrib-nodeunit": "~0.4.1", "grunt-contrib-uglify": "~0.5.0" } }


2015年10月13日 星期二

ng-view angular js template

from:
https://thinkster.io/a-better-way-to-learn-angularjs/ng-view


include  angular-route.js





angular.module('myApp', ['ngRoute'])

.config(function($routeProvider){
  $routeProvider.when("/",
    {
      templateUrl: "app.html",
      controller: "AppCtrl",
      controllerAs: "app"
    }
  );
})

.controller('AppCtrl', function() {
  var self = this;
  self.message = "The app routing is working!";
});


<h1>{{ app.message }}</h1>
<body ng-app="myApp">
  <ng-view></ng-view>
</body>