I have an application with Miller Columns, i.e. a series of lists. Each column of this is a view.

The data is pulled in from a json file with a resolve in the route.

The first column displays a table of the top level data, e.g all the accounts in the data:

_this.costAccounts = CostAccountsResolve;

When a user clicks on a row, I load another route into the view for the second column, passing the account number:

$state.go('miller.subaccount', { accountid: item.account_number });

The route is:

.state('miller', {
    url: '/miller',
    resolve: {
      CostAccountsResolve: function (MockDataFactory) {
        return MockDataFactory.query({ filename: 'cost_accounts' });
      }
    },
    views: {
      ....
    }
  })

.state('miller.subaccount', {
    url: '/subaccount/:accountid',
    views: {
      'subaccounts@miller': {
        controller: 'SubaccountController as sub',
        templateUrl: 'modules/miller/templates/subaccounts.html'
      },
      'crud@miller': {}
    }
  })

So if the user clicks on account number 001 I go to a the subaccount state with id 001: /#/miller/subaccount/001

This should display a table with the subaccounts of account 001. The data is in the format:

[
  {
    "account_number": "001",
    "account_name": "Account 1",
    "subaccounts": [
      {
        "account_number": "00101",
        "account_name": "SubAccount 1 of Account 1"
      },
      {
        "account_number": "00102",
        "account_name": "SubAccount 2 of Account 1"
      }
    ]
  },
  {
    "account_number": "002",
    "account_name": "Account 2",
    "subaccounts": [
      {
        "account_number": "00201",
        "account_name": "SubAccount 1 of Account 2"
      },
      {
        "account_number": "00202",
        "account_name": "SubAccount 2 of Account 2"
      }
    ]
  }
]

This is still stored in the resolve, CostAccountsResolve. So, how do I populate the table in the subaccounts view with the items in the subaccounts key for account 001? In other words, I want 00101 and 00102 in the example json above.

share|improve this question
    
Please explain This is still stored in the resolve, CostAccountsResolve - I don't see any resolve in your state, are you asking about filtering the correct element from the accounts? – Alon Eitan yesterday
    
Sorry, the parent state has the resolve. I edited my question to reflect this. – Steve yesterday
1  
Just to be sure - You need an example of getting the object with account_number == "001"? You can do it with Array.prototype.find() – Alon Eitan yesterday
    
Exactly, but how do I get the current ID to look for with it? – Steve yesterday
    
Please take a look at $routeParams - I think this is what you need to implement you requirement – Alon Eitan yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.