AngularJS - (使用离子框架) - 数据在头标题绑定不工作 [英] AngularJS - (using Ionic framework) - data binding on header title not working

查看:110
本文介绍了AngularJS - (使用离子框架) - 数据在头标题绑定不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是被称为离子的AngularJS基础库( http://ionicframework.com/ )。

I'm using an AngularJS-based library called "Ionic" (http://ionicframework.com/).

这看起来很简单,但它不是为我工作。

This seems simple, but it isn't working for me.

在我的意见之一,我有以下

In one of my views, I have the following

<view title="content.title">
  <content has-header="true" padding="true">
    <p>{{ content.description }}</p>
    <p><a class="button button-small icon ion-arrow-left-b" href="#/tab/pets"> Back to home</a></p>
  </content>
</view>

在控制器上面的观点,我有

In the controller for the above view, I have

angular.module('App', []).controller('DetailCtrl', function($scope, $stateParams, MyService) {

  MyService.get($stateParams.petId).then(function(content) {
    $scope.content = content[0];
    console.log($scope.content.title); // this works!
  });
});

该视图的数据通过一个简单的HTTP GET服务(称为为MyService)加载。

The data for this view is loaded via a simple HTTP GET service (called MyService).

问题是,当我浏览这个页面,

The problem is that when I view this page,

<view title="content.title">

不显示标题。这只是一个空白。据爱奥尼亚文件(<一个href=\"http://ionicframework.com/docs/angularjs/controllers/view-state/\">http://ionicframework.com/docs/angularjs/controllers/view-state/),我觉得我做了正确的事情。

Doesn't display the title. It's just a blank. According to the Ionic documentation (http://ionicframework.com/docs/angularjs/controllers/view-state/), I think I'm doing the right thing.

这是奇怪的是,{{content.description}}的部分作品,但content.title不工作?

It's strange that "{{content.description}}" part works, but "content.title" doesn't work?

另外,是不是因为我是动态加载的内容(通过HTTP GET)?

Also, is it because I'm loading the content dynamically (via HTTP GET)?

推荐答案

下面是一个如何在离子完成这个工作的例子。打开菜单,然后点击关于。当关于页面过渡,你会看到这是解决称号。

Here's a working example of how to accomplish this in Ionic. Open the menu, then click "About". When the "About" page transitions, you will see the title that was resolved.

由于弗洛里安说,你需要使用的服务和解决,以获得预期的效果。然后,注入返回的结果到控制器。有一些下来双方这一点。直到承诺解决国家提供商不会改变路线。这意味着有可能在用户试图改变位置和实际发生的时间的时间的明显的滞后。

As Florian noted, you need to use a service and resolve to get the desired effect. You then inject the returned result into the controller. There are some down sides to this. The state provider will not change the route until the promise is resolved. This means there may be a noticeable lag in the time the user tries to change location and the time it actually occurs.

<一个href=\"http://plnkr.co/edit/p9b6SWZmBKWYm0FIKsXY?p=$p$pview\">http://plnkr.co/edit/p9b6SWZmBKWYm0FIKsXY?p=$p$pview

这篇关于AngularJS - (使用离子框架) - 数据在头标题绑定不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆