如何从templateUrl中的控制器传递数据

时间:2016-05-26 12:47:46

标签: angularjs angular-ui-router

这是我文件中指定的路线:

$xml = @simplexml_load_string($output);
$MPESA_TRX_ID= (string)$xml->MPESA_TRX_ID; 
$MSISDN = (string)$xml->MSISDN;
$AMOUNT = (string)$xml->AMOUNT;

如何从.state( "path", { url: "/{path:.*}", views: { "secondnav": { templateUrl: "/App/View/Partials/_partDetails.html", controller: 'unitDetailsController' }, "body": { controller: 'unitDetailsController', templateUrl: function($scope) { return "/app/View/unitDetails.html"; } } } }) 中的控制器unitDetailsController传递数据?

1 个答案:

答案 0 :(得分:0)

您可以传递以下代码中的数据:

  

ui-router config:

angular
  .module('angularApp', [
    'ngAnimate',
    'ngCookies',
    'ngResource',
    'ngRoute',
    'ngSanitize',
    'ngTouch',
    'ui.router'
  ])
  .config(function($stateProvider, $urlRouterProvider) {
    //
    // For any unmatched url, redirect to /state1
    $urlRouterProvider.otherwise("/state1");
    //
    // Now set up the states
    $stateProvider
      .state('state1', {
        url: "/state1/:id",
        templateUrl: "views/partials/state1.html",
      });
  });
  

<强>模板:

<div ng-controller="RowsCtrl">
    <h1>State 1</h1>
    <p>Id: {{id}}</p>
    <div ui-view></div>
</div>