状态提供程序返回空白ui-view

时间:2017-01-26 15:28:31

标签: angularjs

我有stateProvider,当用户点击按钮时,除了'main.updateWine'之外的所有状态都能正常工作。我在html中的按钮图标上注册了click事件,它在控制器中唤醒函数wlc.updateWine,该控制器使用params调用状态。但结果我得到了空白状态。我再说一遍,除此之外,所有其他州都工作得很好。 代码如下:

this.formService.getMyData()

// CONTROLLER:

(function(){
angular
    .module("winesModule")
    .config(Config);

    function Config($stateProvider){
        $stateProvider
        .state("main.wines",{
            url:"/wines",
            templateUrl:"app/components/wines/wines.html",
            controller: "winesController",
            controllerAs: "wlc"
        })
        .state("main.addWine",{
            url:"/addWine",
            templateUrl:"app/components/wines/addWine.html",
            controller:"addWine",
            controllerAs:"wAw",
            resolve:{
                wine:function(){
                    return{};
                }
            }
        })
/* THIS STATE RETURNS BLANK VIEW*/
        .state("main.updateWine",{
            url:"/updateWine/:id",
            teplateUrl:"app/components/wines/addWine.html",
            controller:"addWine",
            controllerAs:"wAw",
            resolve:{
                wine:function($stateParams, winesService){
                    return winesService.get({id: $stateParams.id})
                }
            }
        });
    }
})();

// HTML -TEMPLATE app / components / wines / addWine.html

function(){

angular
    .module("winesModule")
    .controller("winesController", winesController);

    function winesController(winesService, $state){
        var wlc = this;
        wlc.data = {};

        var onSuccessGet = function(response){          
            wlc.data.wines = response.results;  
        }
        var getWineList = function(){

                winesService.get().$promise.then(onSuccessGet);             
            }
        getWineList();

        wlc.updateWine = function(wine){

            $state.go("main.updateWine", {id : wine._id});
        }
    }

})();

2 个答案:

答案 0 :(得分:1)

尝试使用

更改您的决心
wine: function($stateParams, winesService) {
    return winesService.get({id: $stateParams.id}).$promise;
}

答案 1 :(得分:0)

感谢您的帮助,我终于解决了这个问题。

我已经重新输入导致问题的状态,现在它起作用了,现在仍然没有原因,以及有什么不同。

    .state("main.updateWine",{
            url: "/updateWine/:id",
            templateUrl:"app/components/wines/addWine.html",
            controller:"addWine",
            controllerAs:"wAw",
            resolve: {
                wine:function($stateParams, winesService){
                    return winesService.get({id: $stateParams.id});
                }
            }
        });