【发布时间】:2017-02-03 02:06:02
【问题描述】:
代码如下:
<html>
<head>
<script type='text/javascript'>
var myAppModule = angular.module('myApp', []);
myAppModule.factory('studentFactory', function (){
// The whole factory goes here.
});
myAppModule.controller('studentsController', ['$scope', 'studentFactory', function ($scope, studentFactory){
$scope.students = [];
studentFactory.getStudents(function (data){
$scope.students = data;
});
studentFactory.removeStudent(function (data){
alert('test');
$scope.students = data;
});
}])
</script>
</head>
<body ng-app='myApp'>
...
</body>
</html>
alert('test') 在页面加载时被触发。我该如何解决?请不要介意代码中的问题,我只是在处理它。
这是 Plunker 中的代码:https://plnkr.co/edit/u7c13AIdKPjmdkzRUPXd?p=preview
【问题讨论】:
-
我们能看到.removeStudents 的实现吗?还有.getStudents?它们很可能不是异步的。
-
当然,最好转到我稍后在编辑中提供的 Plunker 中的链接。
-
另外,还没有实现。
-
您希望什么时候解雇 removeStudent?你想在点击事件发生时触发它吗?你想在一段时间后触发它吗?
标签: javascript angularjs