Onsen UI和AngularJS无法从模板访问新的范围变量

时间:2014-11-26 22:02:01

标签: angularjs templates scope onsen-ui

我正在使用PhoneGap + OnsenUI + AngularJS构建一个简单的ios应用程序,并且范围变量存在问题。 我只有一个控制器。

所以...我有一个包含项目的列表,当我点击一个项目时,我在控制器中执行一个函数,传递被点击的对象。 在函数中,我在范围

中分配对象
$scope.newVar = obj

由于某种原因,当我从执行的函数执行pushPage时,在模板文件中我无法访问该新变量,但我可以访问其他页面中的旧变量。 在浏览器调试器中,我可以在$ scope中看到新变量。

我拥有的两个功能是: 第一页是第一页..而showSelectedPics是我遇到的问题。

  $scope.showSubCatPic = function(pic) {
    $scope.currentSubCat = pic.category; // i can access from the 2nd page template
    $scope.currentCat = pic.subs; // i can access from the 2nd page template
    $scope.currentBasedir = pic.basedir; // i can access from the 2nd page template
    mediaNavigator.pushPage('show-sub-cats-pic.html', {
      animation: "slide-left"
    });
  };

  $scope.showSelectedPics = function(sub) {
    $scope.currentPic = sub; // this is the variable that i can't access
    $scope.ons.navigator.pushPage('pictures.html');
  };

第1页的HTML:

<ons-page ng-controller="AppController">
    <ons-toolbar>
        <div class="left"><ons-back-button>Back</ons-back-button></div>
        <div class="center">{{currentSubCat}}</div>
    </ons-toolbar>
        <ons-list class="treatment-list">
            <ons-list-item class="person" modifier="chevron" ng-repeat="sub in currentCat" ng-click="showSelectedPics(sub)">
                <ons-row>
                    <ons-col class="treatment-name">
                        {{sub.title}}
                    </ons-col>
                </ons-row>
        </ons-list-item>
    </ons-list>
</ons-page>

我遇到问题的页面中的HTML:

<ons-page ng-controller="AppController">
    <ons-toolbar>
        <div class="left"><ons-back-button>Back</ons-back-button></div>
        <div class="center">{{currentPic.title}}</div>
    </ons-toolbar>
        <ons-list class="treatment-list">
            <ons-list-item class="person">
                <ons-row>
                    <ons-col class="treatment-name">
                        {{currentPic.title}}
                    </ons-col>
                </ons-row>
            </ons-list-item>
        </ons-list>
</ons-page>

代码有什么问题????如果没有,任何人都可以告诉我如何将对象传递给模板文件。我不介意它是否是错误的方式&#34;去做这个。我只是想做这个工作..

提前致谢。

0 个答案:

没有答案