San*_*ngh 11 html javascript angularjs
以下工作从一个函数调用函数ActiveChange(变量)
a(href="javascript: ActiveChange('topStories');") Top Stories
Run Code Online (Sandbox Code Playgroud)
但是如果函数被定义为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';
}
}
}
Run Code Online (Sandbox Code Playgroud)
你如何调用$ scope.ActiveChange = function(activeTab)?
Max*_*tin 23
就像使用ngClick@Mike说的那样.我没有看到使用角度的原因href.
就像是:
<a href="" ng-click="ActiveChange('topStories');">Top Stories</a>
Run Code Online (Sandbox Code Playgroud)
或者留空:
<a href ng-click="ActiveChange('topStories');">Top Stories</a>
Run Code Online (Sandbox Code Playgroud)