我刚刚开始学习 Angular.js。我正在尝试将函数从 CtrlA 调用到 CtrlB。我怎么做?
这是我到目前为止所拥有的 -
var app = angular.module('myApp', []);
function UserCtrl($scope) {
$scope.users = [
{id: 1, name: 'Mike Smith'},
{id: 2, name: 'Jane Doe'}
];
$scope.getDetails = function(userId) {
//Call getUserById in UserDetailCtrl. How?
};
};
function UserDetailCtrl($scope) {
$scope.getUserById = function(userId) {
alert('test');
};
};
看法 -
<div ng-controller="UserCtrl">
<ul>
<li ng-repeat="user in users">
<a ng-click="getDetails(user.id)">{{user.name}}</a>
</li>
</ul>
</div>
谢谢!