Ionic $ stateParams未定义错误

时间:2015-02-16 08:25:22

标签: angularjs angularjs-ng-repeat angular-ui-router ionic

我是离子和角度的首发,当遵循主 - 细节导航练习时,我发现$ stateParams无法正常工作,当导航到详细信息页面时,似乎stateParams未定义,任何想法?感谢

app.js



var app = angular.module('starter', ['ionic'])
  app.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
  });
})
  app.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider
	  .state('home', {
	    url: "/home",
	    abstract: true,
	    templateUrl: "app/home/views/home.html"
	  })
		  .state('home.leagues',{
			  url:"/leagues",
			  views:{
				  "tab-leagues":{
					  templateUrl:"app/home/views/leagues.html"
				  }
			  }
		  })
		  .state('home.myTeams',{
				url:"/myTeams",
				views:{
					"tab-myTeams":{
						templateUrl:"app/home/views/myTeams.html"
					}
				}
		  })
	  .state('sideMenu', {
		  url:"/sideMenu",
		  abstract: true,
		  templateUrl: "app/home/views/sideMenus.html",
	      controller:"listCtrl"
	  })
		  .state('sideMenu.playlists', {
			  url: "/playlists",
			  views: {
				  "menuContent": {
					  templateUrl: "app/home/views/playlists.html"
				  }
			  }
	  })
	      .state('sideMenu.playlist',{
		      url:"/playlists/:id",
		      views:{
			      "menuContent":{
				      templateUrl:"app/home/views/playlist.html"
			      }
		      }
	        })
	      .state('sideMenu.login',{
		      url:"/login",
		      views:{
			      "menuContent":{
				      templateUrl:"app/home/views/login.html"
			      }
		      }
		  });

  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/home/leagues');
});




masterPage.html



<ion-view view-title="Playlists" ng-controller="listCtrl">
  <ion-content>
    <ion-list>
      <ion-item ng-repeat="playlist in playlists" href="#/sideMenu/playlists/{{playlist.id}}">
        {{playlist.title}}
      </ion-item>
    </ion-list>
  </ion-content>
</ion-view>
&#13;
&#13;
&#13;

detailPage.html

&#13;
&#13;
<ion-view view-title="Playlist" ng-controller="listDetailCtrl">
  <ion-content>
    <h1>{{playlist.title}}</h1>
      <span>isBinded?</span>
      <span>{{isBinded}}</span>
  </ion-content>
</ion-view>
&#13;
&#13;
&#13;

detailCtrl

&#13;
&#13;
app.controller('listDetailCtrl',['$stateParams',function($scope,$stateParams){

	console.log("$stateParams",$stateParams);
	$scope.isBinded = "true";
}]);
&#13;
&#13;
&#13;

0 个答案:

没有答案