1. Trang chủ
  2. » Thể loại khác

Scope trong AngularJS | 26 bài hướng dẫn AngularJs miễn phí PDF

4 85 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

http://vietjack.com/angularjs/index.jsp Copyright © vietjack.com AngularJS - Scope Scope đối tượng JavaScript đặc biệt có vai trò liên kết controller view Scope chứa thông tin liệu model Trong controller, liệu model truy cập qua đối tượng $scope var mainApp = angular.module("mainApp", []); mainApp.controller("shapeController", function($scope) { $scope.message = "In shape controller"; $scope.type = "Shape"; }); Dưới điểm quan trọng ví dụ  $scope truyền tham số controller hàm khởi tạo  $scope.message $scope.type model sử dụng trang HTML  Chúng ta thiết lập giá trị cho model tác động lên Module ứng dụng với controller shapeController  Chúng ta định nghĩa hàm với $scope Tính kế thừa Scope Scope controller riêng biệt Chúng ta định nghĩa nested controller (các controller lồng nhau) để controller kế thừa từ controller cha var mainApp = angular.module("mainApp", []); mainApp.controller("shapeController", function($scope) { $scope.message = "In shape controller"; $scope.type = "Shape"; }); http://vietjack.com/ Trang chia sẻ học online miễn phí Page http://vietjack.com/angularjs/index.jsp Copyright © vietjack.com mainApp.controller("circleController", function($scope) { $scope.message = "In circle controller"; }); Dưới điểm qua ví dụ  Chúng ta tạo giá trị biến model cho shapeController  Chúng ta ghi đè thông báo controller circleController Khi “message” sử dụng module circleController, giá trị message ghi đè sử dụng Ví dụ Dưới phần ví dụ cho phần hướng dẫn bên testAngularJS.jsp Angular JS Forms AngularJS Sample Application

{{message}} {{type}}

{{message}} {{type}}

{{message}} {{type}}

var mainApp = angular.module("mainApp", []); http://vietjack.com/ Trang chia sẻ học online miễn phí Page http://vietjack.com/angularjs/index.jsp Copyright © vietjack.com mainApp.controller("shapeController", function($scope) { $scope.message = "In shape controller"; $scope.type = "Shape"; }); mainApp.controller("circleController", function($scope) { $scope.message = "In circle controller"; }); mainApp.controller("squareController", function($scope) { $scope.message = "In square controller"; $scope.type = "Square"; }); Kết Mở trang textAngularJS.jsp trình duyệt web Và xem kết http://vietjack.com/ Trang chia sẻ học online miễn phí Page http://vietjack.com/angularjs/index.jsp http://vietjack.com/ Trang chia sẻ học online miễn phí Copyright © vietjack.com Page ... mainApp.controller("shapeController", function( $scope) { $scope. message = "In shape controller"; $scope. type = "Shape"; }); mainApp.controller("circleController", function( $scope) { $scope. message = "In circle controller";... http://vietjack.com/ Trang chia sẻ học online miễn phí Page http://vietjack.com /angularjs/ index.jsp http://vietjack.com/ Trang chia sẻ học online miễn phí Copyright © vietjack.com Page ... message ghi đè sử dụng Ví dụ Dưới phần ví dụ cho phần hướng dẫn bên testAngularJS.jsp Angular JS Forms AngularJS Sample Application

Ngày đăng: 02/12/2017, 19:01

Xem thêm:

TỪ KHÓA LIÊN QUAN