繁体   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