在Angular中,将值从resolve传递给控制器

时间:2017-11-14 16:09:16

标签: angularjs angular-ui-router resolve

我正在尝试将此变量传递给控制器​​,然后在屏幕上显示。我不确定为什么我会因为这个值而未定义。我去了类似的SO问题,似乎我做得对。

.state({
                name: "test",
                url: "/testURL",
                views: {
                    'testView': {
                        template: '<div><span>{{testvariable}} </span></div>',
                        controller: "testController",
                        resolve: {
                            testString: function () {
                                debugger;
                                return 'from Resolve';
                            }
                        }
                    }
                },
            })
      })

      app.controller("testController", ["$scope", "$state",

        function ($scope, $state, testString) {
            console.log("getting from resolve ", testString)
            $scope.testvariable = function () {
                console.log("getting from resolve ", testString)
                return testString;
            }
            $scope.testvariable();

        }
      ])

0 个答案:

没有答案