I want to pass a value from one html template to another. I have an API which identifies the username and his role, and I want to send the username value. Per example, this is my code from a file called "payment-component.js"
:
(function(){
'use strict';
var payments = {
templateUrl: './app/component-pay.html',
controller: payCtrl
};
angular
.module('payApp')
.component('payThis', payments);
payCtrl.$inject = ["$scope"];
function payCtrl($scope){
function users (){
//$scope.userName;
$http.get('api/UserRoleUser?sendUserValue=true')
.then(function(data){
$scope.thisUser = data.data.Response;
});
}
}
})();
HTML view:
<div class="title">
<h3><strong>Welcome, {{thisUser}}!</strong></h3>
</div>
I need to pass thisUser
to another file but is not working. The other documents are detail-component.js
:
(function(){
'use strict';
var home = {
templateUrl: './app/component/detail-component/detail.html',
controller: homeCtrl
};
angular
.module('payApp')
.component('home', home);
function homeCtrl(){
var home = this;
}
})();
And it html view (detail.html
):
<div class="title">
<h3><strong>This is your detail, {{userName}}!</strong></h3>
</div>
I'd read a little bit, and I know I have to bind the data from one side to another, but I don't know how to do that. I'm still learning...
Can you help me, please?