2016年11月1日 星期二

AngularJS 技術

(A)angularjs 執行順序:
app.config()
app.run()
directive's compile functions (if they are found in the dom)
app.controller()
directive's link functions (again, if found)

(B)angularjs 超連結做法:

 (b-1) <a ui-sref="profile"><i class="fa fa-fw fa-user"></i> Profile</a>
  裡面的profile 找到對應的 App.js裡面的
  .state('profile', {
            url: '/profile',
            templateUrl: '/views/profile.html',
            parent: 'master',
            requireAuth: true
        })
     
  (b-2)如果有傳遞參數則
    <a ui-sref="home({foo: 'fooVal1', bar: 'barVal1'})">
    對到$stateParams
    .controller('MainRootCtrl', function($scope, $state, $stateParams) {
    //..
    var foo = $stateParams.foo; //getting fooVal
    var bar = $stateParams.bar; //getting barVal
    //..
    $scope.state = $state.current
    $scope.params = $stateParams;
})


(C)services的使用:

http://www.w3schools.com/angular/tryit.asp?filename=try_ng_services_custom

沒有留言:

張貼留言