I am creating ionic app(ionic version v1) with angular js. I want to get the data of clicked element from one html file and use it in other html file.
app.js
angular.module('placementApp', ['ionic'])
.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);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider) {
// $ionicConfigProvider.views.transition('android'); //none, ios
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'templates/main.html'
// controller: 'AppCtrl'
})
.state('students', {
url: '/students',
templateUrl: 'templates/userList.html'
})
.state('companies', {
url: '/companies',
templateUrl: 'templates/companyList.html'
})
.state('editStudent', {
url: '/editStudent',
templateUrl: 'templates/editUser.html'
});
});
userList.component.js
var app = angular.module('placementApp');
app.controller('userListCtrl', function($scope) {
$scope.students = [
{
name: "Pearl Adam",
Branch: "CE",
id: "10562",
cgpa: "5.9"
},
{
name: "Avrill White",
Branch: "CSE",
id: "10821",
cgpa: "8.3"
}
]
$scope.getClickedStudent = function(event) {
$scope.v = event.currentTarget.attributes.data;
console.log($scope.v);
}
})
userList.html
<ion-view>
<ion-header-bar class="bar-stable">
<h1 class="title">Student List</h1>
</ion-header-bar>
<ion-content class="has-header">
<div ng-controller='userListCtrl' ng-init='v = "undefined"'>
<ul class="list" ng-repeat="x in students">
<li class="item">
<a ng-click="getClickedStudent($event)" data='{{x}}' class="item" href='#/editStudent' >
<p>Name: {{x.name}}</p>
<p>Roll No.: {{x.id}}</p>
</a>
</li>
</ul>
{{v.name}}
</div>
</ion-content>
</ion-view>
I need to get the data of clicked element and use it in editUser.html for eg. {{v.name}}, {{v.cgpa}}.
but v is getting {} value.
I am using v in following file and it is showing empty value of {{v}} instead.
editUser.html
<ion-view>
<ion-header-bar class="bar-stable">
<div ng-controller="userListCtrl">
<h1 class="title">{{v.name}}</h1>
</div>
</ion-header-bar>
<ion-content class="has-header">
<div ng-controller='userListCtrl'>
<div class="list">
<label class="item item-input">
<span class="input-label">Name</span>
{{v.name}}
</label>
<label class="item item-input">
<span class="input-label">Branch</span>
{{v.branch}}
</label>
<label class="item item-input">
<span class="input-label">Roll No.</span>
{{v.id}}
</label>
<label class="item item-input">
<span class="input-label">CGPA</span>
{{v.cgpa}}
</label>
</div>
</div>
</ion-content>
</ion-view>