[英]calling a function on pageload angularjs
I created a function on my controller in angularjs which look likes this 我在angularjs的控制器上创建了一个函数,看起来像这样
$scope.pload = function () {
$http.get('/WebServices/manageuser.asmx/showdatamanageuser', {
}).then(function (response) {
$scope.getdata = response.data;
console.log($scope.getdata);
});
}
and i want to call this function after insert,delete and page load, so i called the function like this 我想在插入,删除和页面加载后调用此函数,所以我这样调用了该函数
<script type="text/javascript">
var app = angular.module("myApp", ["ngStorage"]);
app.controller("myCtrl", function ($scope, $http, $interval, $localStorage, $sessionStorage, $window) {
var filename = undefined;
var file = undefined;
var filepath = undefined;
//showing table
$scope.pload();
the error i am getting is 我得到的错误是
TypeError: $scope.pload is not a function
at new <anonymous> (VM190 ManageUser:427)
at Object.invoke (angular.js:4842)
at R.instance (angular.js:10695)
at n (angular.js:9572)
at g (angular.js:8881)
at angular.js:8746
at angular.js:1843
at m.$eval (angular.js:17972)
at m.$apply (angular.js:18072)
at angular.js:1841
what is wrong here? 这是怎么了
Missing declare $scope in angular.module. 在angular.module中缺少声明$ scope 。 Example : 范例:
angular.module('Appcontrollers', []).controller('LoginController', ['$rootScope', '$scope', '$http', function ($rootScope, $scope, $http,) {}
You need to call the function after its definition not before like this : 您需要在其定义之后调用函数,而不是像这样:
$scope.pload = function () {
$http.get('/WebServices/manageuser.asmx/showdatamanageuser', {
}).then(function (response) {
$scope.getdata = response.data;
console.log($scope.getdata);
});
}
$scope.pload();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.