第一次调用angularjs控制器失败

时间:2015-06-02 08:23:28

标签: javascript jquery asp.net-mvc angularjs twitter-bootstrap

我正在开发一个项目,我使用过mvc,bootstrap和angularjs.Everything工作正常,但我遇到的问题是我没有在第一次调用时获取数据但在第二次点击时获取数据.Suppose我有一个链接MyIssues - 然后如果我第一次点击这个链接只有我的静态共享视图出现而休息部分显示为空但在第二次点击eveything工作正常。我没有得到错误在哪里,我的控制台显示没有错误。实际上我尝试了很多东西,发现我的角度控制器已加载,但我的控制器在第一次点击时没有被调用。

以下是我正在使用的控制器 BaseController.js

  var userImagePath;
alert('test');
var app = angular.module('Trackue', ['ngRoute', 'ngSanitize', 'angular-loading-bar', 'ng.deviceDetector', 'ui.bootstrap']);
angular.module('Trackue').filter('fromNow', function () {
alert('common');
return function (date) {
    return moment(date).fromNow();
};
});
  alert('base');
 var baseController = function ($scope, $http) {
alert('base pic');
$scope.UnreadNotificationCount = 0;
$scope.ProfileImagePath = "";
$scope.UnseenNotifications = [];
$scope.myIssueCount = 0;
//Loading User Profile Image
$scope.GetUserProfilePic = function () {
    var url = window.location.protocol + '//' + window.location.host + '/api/Home' + '/GetUserImage/';
    $http.post(url, []).success(function (data, status, headers, config) {
        if (data != '') {
            $scope.ProfileImagePath = JSON.parse(data);
            userImagePath = $scope.ProfileImagePath;
        } else {
            $scope.errors.push(data.error);
        }
    });
};
$scope.GetUserProfilePic();

$scope.GetUnseenUserNotification = function () {
    //        var url = window.location.protocol + '//' + window.location.host + '/api/Home' + '/GetUserNotifications/';
    //        $http.post(url, []).success(function (data, status, headers, config) {
    //            if (data) {
    //                //alert(data);
    //                $scope.UnreadNotificationCount = data.length;
    //                $scope.UnseenNotifications = data;
    //            } else {
    //                $scope.errors.push(data.error);
    //            }
    //        });
};
$scope.GetUnseenUserNotification();

$scope.GetMyIssueCount = function () {
    var url = window.location.protocol + '//' + window.location.host + '/api/Issues' + '/GetMyIssueCount/';
    $http.post(url, []).success(function (data, status, headers, config) {
        if (data) {
            $scope.myIssueCount = data;
        } else {
            $scope.errors.push(data.error);
        }
    });
};
$scope.GetMyIssueCount();
};

MyIssuesController.js

alert("my issues");
 var myIssuesController = function ($scope, $sce, $http, cfpLoadingBar, deviceDetector, $filter, $modal, $log) {
alert("start");
$("#navMyIssues").addClass("active");
$scope.issueCommnets = null;
$scope.showComments = false;
   $scope.Issues = [];
 $scope.dateFormat = 'dd-MMM-yyyy';
$scope.dateTimeFormat = 'dd-MMM-yyyy h:mm:ss a';
$scope.selectedIssue = null;
$scope.statusName = null;
$scope.ProjectDetails = [];
$scope.selectedProject = null;
$scope.isVisible = false;
$scope.isVisibleReply = false;
$scope.notifiedMembers = null;
$scope.defaultProfileImagePath = "";
$scope.pendingIssueCount = 0;
$scope.inprogressIssueCount = 0;
$scope.limitationIssueCount = 0;
$scope.needsresearchIssueCount = 0;
$scope.intestingIssueCount = 0;
//$scope.issueCount = -1;
$scope.issuesLoaded = false;
$scope.issueDetailsLoaded = false;
$scope.modalHeader;
$scope.options;
var selectedTab;
var blob;

 //custom search
function escapeRegExp(string) {
    return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}

$scope.searchIssue = function (item) {
    if (!$scope.query) return true;
    var regex = new RegExp('\\b' + escapeRegExp($scope.query), 'i');
    var itemid;
    if ($scope.query.indexOf("-") > -1) {
        itemid = item.FullId;
    } else {
        itemid = item.FullId.replace("-", "");
    }
    var result = regex.test(itemid);
    if (result) {
        return true;
    }
    else {
        return regex.test(item.Title);
    }
};

$scope.GetDefaultProfilePic = function () {
    alert("1");
    if ($scope.defaultProfileImagePath == "") {
        var url = window.location.protocol + '//' + window.location.host + '/api/Issues' + '/GetDefaultUserProfileImage/';
        $http.post(url, []).success(function (data, status, headers, config) {
            if (data != '' || data.length == 0) {
                $scope.Projects = data;
                if (data != '' || data.length == 0) {
                    $scope.defaultProfileImagePath = $sce.trustAsHtml(angular.fromJson(data));
                } else {
                    $scope.defaultProfileImagePath = "";
                }
            } else {
                $scope.errors.push(data.error);
            }
        });
    }
};
$scope.GetDefaultProfilePic();
 }

0 个答案:

没有答案