Angular - URL正在state.go上更新,但视图未呈现

时间:2016-06-30 08:18:35

标签: javascript angularjs

我试图让网页在点击箭头时更改为相同的状态,但要更新为代表视图中新幻灯片的新对象项。

但是,我的代码如下,我得到了网址更改,但视图没有更新。

奇怪的是......这似乎只发生在第一张幻灯片上,所以如果我点击箭头到下一个问题它就不会更新但是如果我刷新页面就可以点击它对其他问题。

这个工作的另一个实例应该是如果我点击第二个,第三个或第四个项目将我带到滑块然后如果我从那里点击下一个,只要它不是第一个&#39 ; ll将转到下一个对象项。

 // Index of the current item in the items array
    scope.itemIndex = assessment.test.items.indexOf(item._id);
    scope.numberOfItems = assessment.test.items.length;

// Checks if the index is not equal to the length of items
    if (scope.itemIndex !== scope.numberOfItems) {
        var nextItemId = assessment.test.items[scope.itemIndex + 1];
    }

// Checks if the index of the item is not greater than zero
    if (scope.itemIndex > 0) {
        var previousItemId = assessment.test.items[scope.itemIndex - 1];
    }

/**
 * Go to the next question
 */
    scope.next = function () {
        state.go('app.main.3Col.results.details', { itemId: nextItemId, assessmentId: assessment._id }, { refresh: true });
    };

/**
 * Go to the previous question
 */
    scope.previous = function () {
        state.go('app.main.3Col.results.details', { itemId: previousItemId, assessmentId: assessment._id }, { refresh: true });
    };

2 个答案:

答案 0 :(得分:0)

尝试使用选项重新加载

scope.next = function() {
  state.go('app.main.3Col.results.details', {
    itemId: nextItemId,
    assessmentId: assessment._id
  }, {
    reload: true
  });
};

https://github.com/angular-ui/ui-router/wiki/Quick-Reference#stategoto--toparams--options

答案 1 :(得分:0)

好吧..我的坏......我看到出了什么问题......我需要将项目作为一个参数传递,因为它没有更新到下一个项目。执行以下更改已注释修复了我的问题。

        // Checks if the index is not equal to the length of items
    if (scope.itemIndex !== scope.numberOfItems) {
        var nextItemId = assessment.test.items[scope.itemIndex + 1];
        var nextItem = assessmentItems[scope.itemIndex + 1];
    }

    // Checks if the index of the item is not greater than zero
    if (scope.itemIndex > 0) {
        var previousItemId = assessment.test.items[scope.itemIndex - 1];
        // I had to define the previous item and push it through
        var previousItem = assessmentItems[scope.itemIndex - 1];
    }

    /**
     * Go to the next question
     */
    scope.next = function () {
        state.go('app.main.3Col.results.details', { item: nextItem, itemId: nextItemId });
    };