簡體   English   中英

如何將價值傳遞給控制器​​?

[英]How to pass value to the controller?

我試圖將值從Angular的stateProvider傳遞給子控制器。

我有類似的東西

  $stateProvider      
        .state('test', {
            url: '/test',
            views: {
                '': {
                    templateUrl: 'test.html',
                    controller: 'testCtrl',
                    testValue : true
                }
            }
        })

我想從此處將testValue變量傳遞給testCtrl。 我上面的代碼並沒有真正起作用。 有人可以幫我嗎? 非常感謝!

嘗試這個:

 $stateProvider      
    .state('test', {
        url: '/test',
        views: {
            '': {
                templateUrl: 'test.html',
                controller: 'testCtrl',
            }
        },
        resolve : {
           testValue : function()
           {
             return {value : true}
           }
        }
    })

並在testController中:

function testController($scope,........,testValue){
   $scope.value = testValue.value;
}

更多信息在這里

您還可以使用data屬性來代替解析。 在此處查看文檔https://github.com/angular-ui/ui-router/wiki/Nested-States-%26-Nested-Views#inherited-custom-data

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM