国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

對angularJs中controller控制器scope父子集作用域的實例講解

2019-11-19 12:47:03
字體:
來源:轉載
供稿:網友

1.ctrl1是父級控制器,ctrl2和ctrl3都是ctrl1的子級控制器,

2.父級ctrl1中name值的改變會影響ctrl2和ctrl3中name值的改變,

3.但是ctrl2有自己的name輸入傳的值,不會影響ctrl1和ctrl3,這就是繼承隔離,

4.ctrl3無name賦值就繼承父級ctrl1中的name的值。

一、繼承隔離的情況

<div ng-app="module"> <div ng-controller="ctrl1">  {{name}}<input type="text" ng-model="name">  <div ng-controller="ctrl2">   {{name}}<input type="text" ng-model="name">  </div>  <div ng-controller="ctrl3">   {{name}}  </div> </div></div><script> var m = angular.module('module', []); m.controller('ctrl1', ['$scope', function ($scope) {  $scope.name = '泠泠在路上' }]); m.controller('ctrl2', ['$scope', function ($scope) { }]); m.controller('ctrl3', ['$scope', function ($scope) { }]);</script>

運行結果:

angularJs controller scope

二、繼承但不隔離

在ctrl2中改變name的值,既影響自己的值,也影響父級的值。

代碼:

<div ng-app="module"> <div ng-controller="ctrl1">  {{data.name}}<input type="text" ng-model="data.name">  <div ng-controller="ctrl2">   {{data.name}}<input type="text" ng-model="data.name">  </div>  <div ng-controller="ctrl3">   {{data.name}}  </div> </div></div><script> var m = angular.module('module', []); m.controller('ctrl1', ['$scope', function ($scope) { /* 定義對象*/  $scope.data={name:'泠泠在路上'} }]); m.controller('ctrl2', ['$scope', function ($scope) { }]); m.controller('ctrl3', ['$scope', function ($scope) { }]);</script>

運行結果:

angularJs controller scope

以上這篇對angularJs中controller控制器scope父子集作用域的實例講解就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乌审旗| 肥乡县| 孟州市| 呼玛县| 黑龙江省| 威海市| 库伦旗| 清丰县| 双流县| 娱乐| 莱西市| 舒城县| 泗阳县| 聂拉木县| 泾源县| 赣州市| 广东省| 高唐县| 邵武市| 凤阳县| 中江县| 墨脱县| 开远市| 公主岭市| 维西| 阜南县| 高邮市| 高密市| 得荣县| 江达县| 壤塘县| 阿图什市| 天镇县| 五常市| 瑞丽市| 榆树市| 绥宁县| 宜州市| 白水县| 白水县| 宜州市|