android - master details控件在新页面不显示内容

标签 android angularjs html ionic-framework

我正在尝试通过单击按钮查看给定数据的详细信息来进行主详细信息导航

page1.html

<a class="button icon button-block button-calm icon-right ion-android-arrow-dropright-circle" ng-class="{'button-balanced': file.status == 'open', 'button-assertive': file.status == 'closed'}" href="#filedetails" ng-repeat="file in file | orderBy:'-status'" ng-click="onSelectFile(n)" >File Ref No:{{file.num}}<br>
        Description:{{file.descript}}<br>
        Status:{{file.status}}</a><br>

page2.html

<div class="col">: {{file.num}}</div>
      <div class="col">: {{file.casedet}}</div>

Controller 页面

.controller('caseFileCtrl', function($scope,$http,$location) {
     $scope.file=[
        {num:"1",descript:"consumer",status:"closed",casedet:"cleared"},
        {num:"2",descript:"literal",status:"open", casedet:"process"},
        {num:"3",descript:"literal",status:"closed", casedet:"cleared"},
        {num:"4",descript:"consumer",status:"open",casedet:"proess"}
                 ];
$scope.onSelectFile = function(n)
{
    $location.url('/casefile/'+ n.num);
}



 })

  .controller('fileDetailsCtrl', function($scope,$stateParams) {
    $scope.file={num:$stateParams.num, casedet:'file'+$stateParams.casedet};

  })

我无法在其他页面查看 num 和 cadeset

提前致谢

最佳答案

您可以使用服务在 Controller 之间共享数据。

js/services.js

angular.module('starter.services', [])

.factory('File', function($log) {
    this.files = [];
    return {
        /**
         * Get the list of files.
         * @returns Returns the list of files.
         */
        get: function(){
            return this.files;
        },
        /**
         * Set the list of files.
         * @param files The files to set.
         */
        set: function(files){
            this.files = files;
        }
    };
});

在您的 index.html 中包含:

<!-- Your scripts -->
<script src="js/services.js"></script>

在你的 app.js 依赖项中包含:

angular.module('yourModuleName', [/* Your dependencies */, 'starter.services'])

app.js 的配置部分

.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider

    .state('app', {
    url: '/app',
    abstract: true,
    templateUrl: 'templates/menu.html',
    controller: 'AppCtrl'
  })

    .state('app.caseFileCtrl', {
      url: '/casefile',
      views: {
        'menuContent': {
          templateUrl: 'templates/files.html',
          controller: 'caseFileCtrl'
        }
      }
    })

  .state('app.single', {
    url: '/casefile/:fileId',
    views: {
      'menuContent': {
        templateUrl: 'templates/file.html',
        controller: 'fileDetailsCtrl'
      }
    }
  });
  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/app/casefile');
});

js/controllers.js 中使用您的 File 服务

angular.module('starter.controllers', [])

.controller('caseFileCtrl', function($scope, File, $state) {
  $scope.files = [
    {num:"1",descript:"consumer",status:"closed",casedet:"cleared"},
    {num:"2",descript:"literal",status:"open", casedet:"process"},
    {num:"3",descript:"literal",status:"closed", casedet:"cleared"},
    {num:"4",descript:"consumer",status:"open",casedet:"proess"}
  ];

  File.set($scope.files);

  $scope.onSelectFile = function(n){
    console.log("Go to:", '/casefile/'+ n);
    $state.go("app.single", {fileId: n});
  };

})

.controller('fileDetailsCtrl', function($scope, $stateParams, $filter, File) {
    console.log("fileId:", $stateParams.fileId);
    $scope.file = $filter('filter')(File.get(), {num: $stateParams.fileId})[0];
});

您可以在 plunker 上看到可行的解决方案.

一些额外的要点:

  • 避免使用 ng-repeat="file in file"。我更喜欢这样的东西:ng-repeat="file in files"
  • 最好使用 $state.go 而不是 $location 重定向到另一条路线;
  • 如果您在 a 标签上使用 ng-click 指令并使用它重定向到另一个 View ,最好不要包含 href= "#filedetails" 属性以避免双重重定向;
  • a 元素列表没问题,但也可以查看 ion-list .

关于android - master details控件在新页面不显示内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34101483/

相关文章:

android - 同一 Activity 的多个通知

android - 从图库接收 ACTION_SEND Intent

android - 根据手机选择文本

javascript - 使用 Angular 根据选定的过滤器选项填充表格

html - 如何使用类来设计 HTML 表单的样式?

android - 错误 :failed to find Build Tools revision 23. 0.0 rc3

javascript - Angular 指令测试在 IIFE 中包装后失败

angularjs - 在 ionic 中安装 angular-gettext 的演练

html - 如何正确居中和旋转 SVG 圆并将多边形居中于圆心?

PHP在顺序包含文件时插入奇怪的空间