1

index.html

<div class="center" ng-controller="DescriptionController">
<p>{{perigrafi}}</p></div>

app.js

 app.controller('DescriptionController', function($scope, dataPassingService) {

    $scope.description = dataPassingService.get();
    var perigrafi = $scope.description.Description_en;
    var onoma = $scope.description.Name_en;
    alert("the description is " + perigrafi);
});

The datapassing service is function that passing data between controllers.The alert work perfect but when I try to show the perigrafi in html file is not work any suggestions? Thanks in advance.

3 Answers 3

2

perigrafi must be in $scope in your case like $scope.perigrafi

app.controller('DescriptionController', function($scope, dataPassingService){
    $scope.description = dataPassingService.get();
    $scope.perigrafi = $scope.description.Description_en;
    var onoma = $scope.description.Name_en;
    alert("the description is " + perigrafi);
});
Sign up to request clarification or add additional context in comments.

1 Comment

@AntonisKountouretis glad to help ;)
0

Angular.js two way binding for variables work only for those variables which are defined over scope. Since you have defined perigrafi as a local variable, therefore it is not getting binded into html as you are expecting. Put your variable perigrafi on $scope as $scope.perigrafi as suggested by @rkalita.

app.controller('DescriptionController', function($scope, dataPassingService) {
  $scope.description = dataPassingService.get();
  $scope.perigrafi = $scope.description.Description_en;
  var onoma = $scope.description.Name_en;
  alert("the description is " + $scope.perigrafi);
});

Comments

-1

Well you can directly use $scope.description object in your html without creating new unnecessary variable

$scope.description.Description_en // for var perigrafi

$scope.description.Name_en; //  for var onoma

and in HTML you can do like this

<p>{{description.Description_en}}</p>
<p>{{description.Name_en}}</p>

1 Comment

The question is not about wether he can use it directly or not. Its about why is it not getting binded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.