zoukankan      html  css  js  c++  java
  • Angular1.63 绑定数据与继承

    html 部分

    <body ng-app="myapp">
    <div ng-controller="asd">
    <p><span ng-bind="firstName"></span></p>
    </div>
    <div ng-controller="qwe">
    <p><span ng-bind="firstName"></span></p>
    </div>

    ---------------------------------

    script部分


    <script src="js/angular.min.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
    var  app = angular.module("myapp", []); 
    app.controller('asd', function($scope) {    //$scope数据 类似vue中的data
    $scope.firstName = "John";    // 绑定数据 必须是$scope.xx=xx
    $scope.lastName = "Doe"; })// 绑定数据
    app.controller('qwe', function($scope) {    //$scope数据 类似vue中的data
    $scope.firstName = "zlt";    // 绑定数据 必须是$scope.xx=xx
    $scope.lastName = "Doe"; })

    ---------------------

    ng-controller   一个页面上可以有多个,还可以嵌套使用,存在父子关系

    例如

    <div ng-controller="asd">
    <p><span ng-bind="firstName"></span></p>
    <div ng-controller="qwe">
    <p><span ng-bind="firstName"></span></p>   ////john
    </div>
    </div>

    嵌套了一个ng-controller="qwe"

    ---------------

    <script type="text/javascript">
    var  app = angular.module("myapp", []); 
    app.controller('asd', function($scope) {    //$scope数据 类似vue中的data
    $scope.firstName = "John";    // 绑定数据 必须是$scope.xx=xx
    $scope.lastName = "Doe"; })// 绑定数据
    app.controller('qwe', function($scope) {    //$scope数据 类似vue中的data
    $scope.apple = "123123";    // 绑定数据 必须是$scope.xx=xx
    $scope.apples = "543"; })// 绑定数据
    </script>

    子 ng-controller="qwe"的 ng-bind="firstName" 就是 父级的 john

    -----------------------------

  • 相关阅读:
    LeetCode 226. Invert Binary Tree
    LeetCode 221. Maximal Square
    LeetCode 217. Contains Duplicate
    LeetCode 206. Reverse Linked List
    LeetCode 213. House Robber II
    LeetCode 198. House Robber
    LeetCode 188. Best Time to Buy and Sell Stock IV (stock problem)
    LeetCode 171. Excel Sheet Column Number
    LeetCode 169. Majority Element
    运维工程师常见面试题
  • 原文地址:https://www.cnblogs.com/nns4/p/6999622.html
Copyright © 2011-2022 走看看