简体   繁体   中英

$scope in controller is not accessible in view / data binding not working (IONIC/ANGULAR)

In my controller:

.controller('ContactCtrl', function($scope, $stateParams, lodash) {

$scope.selectedContact = lodash.findWhere($scope.businesscards, { Id: parseInt($stateParams.contactId) });

console.log($scope.selectedContact);
 });

In my View:

<div class="item">
{{ $scope.selectedContact }}
<h2>{{ $scope.selectedContact.Full_Name }}</h2>
<p>{{ $scope.selectedContact.Company | uppercase }}</p>
</div>

Why I cannot access $scope.selectedContact and even $stateParams.contactId in my view?

$scope is the connector between the controller and view. In your case you are defining "selectedContact" variable with $scope when you need to print in controller then you need to do like this ( $scope.selectedContact ) or in view you can simple do {{selectedContact}}

使用{{ var }}访问视图中的$scope.var

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM