angularjs怎么初始化一個函數
3 回答

呼如林
TA貢獻1798條經驗 獲得超3個贊
連續批量賦值可以用memsetcharA[20];memset(A[2],'A',5);//對數組A第3個元素開始的連續5個元素統一賦值為字符'A'如果每個需要賦值的元素都不同,就只能一個個賦值了。

料青山看我應如是
TA貢獻1772條經驗 獲得超8個贊
123456789101112131415161718192021222324252627282930313233343536373839 | <!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,這個是默認的,其實你不寫也是false。這樣drective繼承了父scope,所以可以調用父作用域的方法,而聲明新的scope即scope:{}形式就不會繼承了,不過你依然可以用scope.$parent.myFunction()的方式調用。
- 3 回答
- 0 關注
- 774 瀏覽
添加回答
舉報
0/150
提交
取消