第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

請(qǐng)問(wèn)AngularJS中的ng-controller是什么?

請(qǐng)問(wèn)AngularJS中的ng-controller是什么?

大話西游666 2019-09-04 10:06:12
AngularJS中的ng-controller是什么
查看完整描述

4 回答

?
慕的地6264312

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超6個(gè)贊

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>test</title>

<script src="angular.min.js"></script>

<script>

var myApp = angular.module("myApp", []);

    myApp.directive('testIt',function(){

        return {

            restrict: 'A',

            scope: false,

            link:function(scope, elm, attr){

                if(scope.$last){

                    elm.css('color','red');

                    scope.myFunction();

                }

            }

        }

    });

    myApp.controller("testCtrl", function($scope){

        $scope.items = [0,1,2,3,4];

        $scope.myFunction = function(){

            console.log('Hello!');

        };

    });

</script>

</head>

  

<body>

<div ng-app="myApp">

  <div ng-controller="testCtrl">

    <ul>

      <li ng-repeat="item in items" test-it >{{item}}</li>

    </ul>   

  </div>

</div>

</body>

</html>

 主要在于12行的scope:false,這個(gè)是默認(rèn)的,其實(shí)你不寫(xiě)也是false。這樣drective繼承了父scope,所以可以調(diào)用父作用域的方法,而聲明新的scope即scope:{}形式就不會(huì)繼承了,不過(guò)你依然可以用scope.$parent.myFunction()的方式調(diào)用。


查看完整回答
反對(duì) 回復(fù) 2019-09-07
?
BIG陽(yáng)

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊

A',
scope: false,
link:function(scope, elm, attr){
if(scope.$last){
elm.css('color','red');
scope.myFunction();
}
}
}
});
myApp.controller("testCtrl", function($scope){
$scope.items = [0,1,2,3,4];
$scope.myFunction = function(){
console.log('Hello!');
};
});
</script>

查看完整回答
反對(duì) 回復(fù) 2019-09-07
  • 4 回答
  • 0 關(guān)注
  • 1562 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)