0
我的console.log語句顯示$ scope.selectedUser在條件期間有一個值,在我的函數$ scope.showUserPets中沒有定義。這怎麼可能,我該如何解決?
var myApp = angular.module("Pets");
myApp.controller("MainCtrl", function($scope, $routeParams, $http) {
$scope.selectedUser = $routeParams.user;
if ($scope.selectedUser && $scope.info) {
console.log("Has user and doing showUserPets: " + $scope.selectedUser); // user = user1
$scope.showUserPets();
}
$scope.init = function() {
// Sets $scope.info via $http.get
}
$scope.showUserPets() = function() {
for (var i = 0; i < ($scope.info).length; i++) {
console.log($scope.selectedUser + " " + $scope.info[i].user); // $scope.selectedUser is undefined.
}
在$ scope.showUserPets()=函數(){...刪除()在$ scope.showUserPets()...使用$範圍。 showUserPets = function(){... –