请教一个angularjs中在指令调用controller方法的问题
1个回答
展开全部
<!doctype html>
<html ng-app="app">
<head>
</head>
<body>
<div ng-controller="MyCtrl">
<greeting aa="sayHello(name)"></greeting><br>
<greeting aa="sayHello(name)"></greeting><br>
<greeting aa="sayHello(name)"></greeting><br>
</div>
<script src="angular.min.js"></script>
<script src="js/cc.js"></script>
</body>
</html>
var app = angular.module('app', []);
app.controller('MyCtrl', function($scope){
$scope.sayHello = function(name) {
alert("Hello"+name);
}
})
app.directive("greeting", function(){
return {
scope: {
greet: '&aa'
},
restrict: "AE",
template: '<input type="text" ng-model="username"><br><button ng-click="greet({name:username})">click</button>'
}
});
<html ng-app="app">
<head>
</head>
<body>
<div ng-controller="MyCtrl">
<greeting aa="sayHello(name)"></greeting><br>
<greeting aa="sayHello(name)"></greeting><br>
<greeting aa="sayHello(name)"></greeting><br>
</div>
<script src="angular.min.js"></script>
<script src="js/cc.js"></script>
</body>
</html>
var app = angular.module('app', []);
app.controller('MyCtrl', function($scope){
$scope.sayHello = function(name) {
alert("Hello"+name);
}
})
app.directive("greeting", function(){
return {
scope: {
greet: '&aa'
},
restrict: "AE",
template: '<input type="text" ng-model="username"><br><button ng-click="greet({name:username})">click</button>'
}
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询