[英]AngularJS: directive adds object to $scope but undefined in controller
I'm new to AngularJS. 我是AngularJS的新手。 I wanna use angular-bootstrap-tour to create a walk-through. 我想使用angular-bootstrap-tour创建一个演练。 It says: 它说:
The tour directive creates a wrapper that contains all tour steps and adds the tour object to the scope. tour指令创建一个包装,其中包含所有游览步骤,并将游览对象添加到范围。
So I have this code in my view: 所以我认为这段代码:
<div tour placement="top">
<div tour-step order="0" title="Main Menu" content="This is the main menu." placement="bottom">
</div>
And now in my controller, I wanna use this code to start the tour as the page loads: 现在,在我的控制器中,我想使用此代码在页面加载时开始游览:
$scope.tour.restart(tour);
But it says: $scope.tour is undefined!
但是它说: $scope.tour is undefined!
and when I add the code below to my view, the buttons start the tour! 当我将以下代码添加到视图中时,这些按钮将开始导览! How tour is defined in view but not in controller's $scope
? 如何在视图中定义游览,但未在控制器的$scope
定义游览?
<button class="btn" ng-click="tour.restart(true)">Start Tour</button>
Add Code in your js file like 在您的js文件中添加代码,例如
function execute(moduleType) {
if(moduleType) {
var tour = new Tour({orphan: false});
tour.addSteps(setRoute(moduleType));
tour.init();
tour.restart();
tour.start(true);
}
}
Add Code in your HTML file like 在您的HTML文件中添加代码,例如
<button class="btn" ng-click="execute(true)">Start Tour</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.