[英]How do you call an AngularJS $scope.Function from href?
The following works to call a function ActiveChange(variable) from a 以下工作从一个函数调用函数ActiveChange(变量)
a(href="javascript: ActiveChange('topStories');") Top Stories
But if the function is defined as an AngularJS $scope function such as 但是如果函数被定义为AngularJS $ scope函数,例如
function activeController ($scope) {
$scope.topStories='active';
$scope.mostRecent='lucky';
$scope.ActiveChange = function (activeTab) {
if(activeTab=='topStories'){
var x=document.getElementById("someinput");
x.value='happy to be alive';
$scope.topStories='active';
$scope.mostRecent='';
}
else {
alert('else');
$scope.topStories='happy';
$scope.mostRecent='active';
}
}
}
How do you call $scope.ActiveChange = function (activeTab) from the ? 你如何调用$ scope.ActiveChange = function(activeTab)?
Just use ngClick
like @Mike says. 只需像@Mike那样使用
ngClick
。 I don't see the reason to use angular in href
. 我没有看到在
href
使用角度的原因。
Something like: 就像是:
<a href="" ng-click="ActiveChange('topStories');">Top Stories</a>
Or leave it empty: 或者留空:
<a href ng-click="ActiveChange('topStories');">Top Stories</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.