angular.js:12783错误:无法解决' ....'来自州

时间:2016-10-24 08:57:47

标签: javascript angularjs angular-ui-router

我是AngularJS的初学者,并试图绕过ui-router和状态。我在仪表板项目中工作,其中仪表板页面有两个版本1)学生和2)公司。学生版有一个俏皮的主题,而企业有更多的企业风格。此外,一些公司功能隐藏在学生版本中,主要是侧面菜单栏,仅存在于公司中。通过代码,两个版本都是从同一个页面呈现的......dashboard.html和dashboard.js。我已使用ng-ifng-classng-show在dashboard.html中隐藏了公司的学生版本。像这样...... ng-show="Student"ng-show="corporate"等等。我通过将studentcorporate类应用于<body>标记来维护版本的样式。 现在我面临的挑战是,我希望能够通过下拉菜单在这两个版本之间切换。如果用户点击学生,则在下拉菜单中显示学生版本页面,如果点击了公司,则会显示公司版本。这是执行此操作的代码。

$scope.$watch('$root.studentUser', function() {
    if ($rootScope.studentUser == undefined) {
        $scope.Student = user.student;
    } else {
        $scope.Student = $rootScope.studentUser;
    }
    if ($scope.Student) {
        $("body").removeClass("corporate").addClass("student");
    } else {
        $("body").removeClass("student").addClass("corporate");
    }
});

此代码工作正常,我可以在两个版本之间切换。但是我知道我错过了一些东西,因为现在公司版本中的侧面菜单不起作用并抛出错误angular.js:12783 Error: Could not resolve '...' from state。还有一些数据没有正确重新加载。我想我应该使用$state.go$state.transition来完成转换。但我似乎无法理解需要做些什么。任何建议或参考链接。 国家配置......

if (user.student){
        $urlRouterProvider.otherwise("/explore");
        $stateProvider.state('explore', {
          url: "/explore",
          templateUrl: "/static/site/templates/explore.html"
        });
      } else {
        $urlRouterProvider.otherwise("/dashboard");
        $stateProvider.state('dashboard', {
          url: "/dashboard",
          templateUrl: "/static/site/templates/dashboard.html",
        }).state('explore', {
          url: "/explore",
          templateUrl: "/static/site/templates/explore.html"
        }).state('setting', {
          url: "/setting",
          templateUrl: "/static/site/templates/setting.html",
        });
      }

选择标记是Kendo下拉组件

$scope.headerDropdownOpt = {
    dataSource: ds,
    valueTemplate: user.is_student? currentUser.userName : currentUser.name,
    dataTextField: "text",
    dataValueField: "value",
    select: function(e){
        var value = this.dataItem(e.item.index()).value;
        if (value == "profile") {
            __gah_select_profile_option(value);
            $state.go('profile');
        } else if (value == "admin") {
            $scope.$apply(function() {
                user.is_student = false;
                $rootScope.studentUser = user.is_student;
                // Replace Admin View to Student View
                ds.splice(ds.length-2,1,{text: $scope.student_view, value: "student"});
            });
        } else if (value == "student") {
            $scope.$apply(function() {
                user.is_student = true;
                $rootScope.studentUser = user.is_student;
                // Replace Student View to Admin View
                ds.splice(ds.length-2,1,{text: $scope.normal_view, value: "admin"});
            });
        }
    }
}

0 个答案:

没有答案