在3分24秒 讲的这里 我不想让方法名字是loadData和loadData2不行吗
我两个方法都叫loadData 不行吗 然后loadData里面console log的东西不一样 然后在link里面直接调用loadData方法 就不用在leader标签 内和 howtoload了 这样不行吗?这种方法跟老师写的方法有什么区别呢 有大神给解释一下吗
我两个方法都叫loadData 不行吗 然后loadData里面console log的东西不一样 然后在link里面直接调用loadData方法 就不用在leader标签 内和 howtoload了 这样不行吗?这种方法跟老师写的方法有什么区别呢 有大神给解释一下吗
2016-10-29
<!DOCTYPE html>
<html ng-app="MyModule">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src="Angularjs/angular-1.3.0.js"></script>
</head>
<body>
<div ng-controller="MyCtrl">
<loader >滑动加载</loader>
</div>
<div ng-controller="MyCtrl2">
<loader >滑动加载</loader>
</div>
</body>
</html>
<script type="text/javascript">
var myModule=angular.module("MyModule",[]);
myModule.controller('MyCtrl',['$scope',function($scope){
$scope.loadData=function(){
console.log("加载数据中...");
}
}]);
myModule.controller('MyCtrl2',['$scope',function($scope){
$scope.loadData2=function(){
console.log("加载数据中...222");
}
}]);
myModule.directive("loader",function(){
return{
restrict:"AE",
link:function(scope,element,attr){
element.bind("mouseenter",function(){
//scope.loadData();
scope.$apply("loadData()");
scope.$apply("loadData2()");
});
}
}
});
</script>
我这样可以运行,跟加howtoload方法有什么不同吗
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <script src="js/1.6/angular.js"></script> </head> <body ng-app="myApp"> <div ng-controller="myCtrl"> <h2> <loader>加载数据....</loader> </h2> </div> <div ng-controller="myCtrl2"> <h2> <loader>加载数据....222</loader> </h2> </div> <script> var app = angular.module("myApp",[]); app.controller("myCtrl",function($scope){ $scope.loadData = function(){ console.log("加载数据....111"); } }) app.controller("myCtrl2",function($scope){ $scope.loadData = function(){ console.log("加载数据....222"); } console.log(window) }) app.directive("loader",function(){ return { restrct: "AE", link:function(scope,element,attr){ element.bind("mouseenter",function(){ scope.loadData(); }) } } }) </script> </body> </html>
可以写一样的loadData啊,我试了都能输出,是版本不同么?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body ng-app="myApp">
<div ng-controller="myCtrl">
<loader howToLoad="loadData()">滑动加载</loader>
</div>
<div ng-controller="myCtrl2">
<loader howToLoad="loadData()">滑动加载</loader>
</div>
<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
<script>
var app=angular.module("myApp",[]);
app.controller("myCtrl",["$scope",function ($scope) {
$scope.loadData=function () {
console.log("数据加载中。。。。。。")
}
}]);
app.controller("myCtrl2",["$scope",function ($scope) {
$scope.loadData=function () {
console.log("数据加载中222。。。。。。")
}
}]);
app.directive("loader",function () {
return{
restrict:"AE",
link:function (scope, element, attr) {
element.bind("mouseenter",function () {
scope.$apply(attr.howtoload);
})
}
}
})
</script>
</body>
</html>
举报