Html 你如何从 href 调用 AngularJS $scope.Function?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17985327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you call an AngularJS $scope.Function from href?
提问by Sangram Singh
The following works to call a function ActiveChange(variable) from a
以下工作从一个函数调用 ActiveChange(variable)
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) ?
回答by Maxim Shoustin
Just use ngClick
like @Mike says. I don't see the reason to use angular in href
.
ngClick
就像@Mike 说的那样使用。我没有看到在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>