以下用于从
调用函数ActiveChange(变量)a(href="javascript: ActiveChange('topStories');") Top Stories
但是如果函数被定义为AngularJS $范围函数,例如
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';
}
}
}
如何从?
调用$ scope.ActiveChange = function(activeTab)答案 0 :(得分:23)
只需使用ngClick
就像@Mike说的那样。我没有看到在href
中使用角度的原因。
类似的东西:
<a href="" ng-click="ActiveChange('topStories');">Top Stories</a>
或者留空:
<a href ng-click="ActiveChange('topStories');">Top Stories</a>