pushPage无法正常工作 - Onsen monaca phonegap

时间:2015-06-27 06:04:47

标签: angularjs cordova phonegap-build onsen-ui monaca

JS

app.controller('categoryController', function($scope,$http){
    $http.get('http://xxxxxxxxxxxx.com/public/api/v1/category').success(function(response){
        $scope.myCategory = response.data;
    });

    $scope.showSubCategory = function(index) {
        var selectedItem = $scope.myCategory[index];
        var options = { animation: 'slide' };

        $scope.myCategory.selectedItem = selectedItem;

        $scope.ons.navigator.pushPage('subcategory.html', options, {name : selectedItem.name}); 
    };
});

HTML /角/温泉

  <ons-navigator>
    <ons-page>
        <ons-toolbar>
            <div class="left">
                <ons-toolbar-button ng-click="app.slidingMenu.toggleMenu()"><ons-icon icon="bars"></ons-icon></ons-toolbar-button>
            </div>
            <div class="center">Home</div>
            <div class="right">
                <ons-toolbar-button ng-click="app.slidingMenu.toggleMenu()"><ons-icon icon="fa-search"></ons-icon></ons-toolbar-button>
            </div>
        </ons-toolbar>


        <ons-list ng-controller="categoryController" id="category-lists">
            <ons-list-item modifier="chevron" class="item" ng-repeat="item in myCategory" ng-click="showSubCategory($index)">
                <ons-row>
                    {{item.name}}
                </ons-row>                          
            </ons-list-item>
        </ons-list>

    </ons-page>   
  </ons-navigator>

错误

TypeError:无法调用方法&#39; pushPage&#39;未定义的     在Scope。$ scope.showSubCategory(file:///data/data/com.example.helloworld/files/projects/cloud/558d3c277e2193c742d69fea/www/components/app.js:16:27)     在file:///data/data/com.example.helloworld/files/projects/cloud/558d3c277e2193c742d69fea/www/components/loader.js:1439:30512     在file:///data/data/com.example.helloworld/files/projects/cloud/558d3c277e2193c742d69fea/www/components/loader.js:1448:18904     在Scope。$ eval(file:///data/data/com.example.helloworld/files/projects/cloud/558d3c277e2193c742d69fea/www/components/loader.js:1437:28127)     在Scope。$ apply(file:///data/data/com.example.helloworld/files/projects/cloud/558d3c277e2193c742d69fea/www/components/loader.js:1437:28433)     在HTMLElement.listener(文件:///data/data/com.example.helloworld/files/projects/cloud/558d3c277e2193c742d69fea/www/components/loader.js:1448:18886)     在HTMLElement.eventHandler(file:///data/data/com.example.helloworld/files/projects/cloud/558d3c277e2193c742d69fea/www/components/loader.js:1434:29261)     在FastClick.sendClick(文件:///data/data/com.example.helloworld/files/projects/cloud/558d3c277e2193c742d69fea/www/components/loader.js:1441:13284)     在FastClick.onTouchEnd(file:///data/data/com.example.helloworld/files/projects/cloud/558d3c277e2193c742d69fea/www/components/loader.js:1441:17447)     在HTMLBodyElement。 (文件:///data/data/com.example.helloworld/files/projects/cloud/558d3c277e2193c742d69fea/www/components/loader.js:1441:10005)


嗨,我使用了monaca.pushPage(subcategory.html,.....)并且没有错误,但无法移动到subcategory.html页面。

任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

ons变量不再存储导航器。您必须在导航器中使用var属性并为其命名,以便稍后调用它。例如:

<ons-navigator var="myNavigator">
    ...
</ons-navigator>

然后将其与myNavigator.pushPage(...)一起使用。更多信息:http://onsen.io/reference/ons-navigator.html

希望它有所帮助!