如果在url参数id可用,那么我想调用函数。
.controller('repeatCtrl', function($scope,$state,$stateParams) { if($stateParams.id != ""){ //Here i want to call itemDetails function $scope.itemDetails(id); }; $scope.itemDetails = function(id) { // function body here!! alert(id); }; })
答案 0 :(得分:2)
问题是你在声明它之前正在调用一个函数。
.controller('repeatCtrl', function($scope,$state,$stateParams) {
$scope.itemDetails = function(id) {
// function body here!!
alert(id);
};
if($stateParams.id && $stateParams.id != ""){
//Here i want to call itemDetails function
$scope.itemDetails(id);
};
})