我想在HTML中显示一些属性。当Angular绑定它所显示的属性时,问题是透明的。 当我调试时,变量“vm.cancha”从另一个控制器接收数据:
控制器:
(function() {
'use strict';
angular
.module('example.infocancha')
.controller('InfoCanchaController', InfoCanchaController);
InfoCanchaController.$inject = ['$stateParams'];
function InfoCanchaController($stateParams) {
var vm = this;
vm.cancha = [];
vm.obtenerInformacionCancha, obtenerInformacionCancha;
inicializar();
function inicializar() {
obtenerInformacionCancha();
}
//funcion para obtener la cancha seleccionada
function obtenerInformacionCancha() {
vm.cancha = angular.fromJson($stateParams.cancha);
debugger;
}
}
})();
查看:
<ion-view view-title="{{cancha.nroCancha}}">
<ion-content>
<h3 class="content-horizontal-padding">{{cancha.descripcion}}</h3>
<div class="list card">
<a class="item item-icon-left">
<i class="icon ion-email"></i>
{{cancha.descripcion}}
</a>
</div>
</ion-content>
</ion-view>
同样在我的示例模块中,我有:
(function() {
'use strict';
angular
.module('example.infocancha', [
'ionic',
'ngCordova',
'example.comun'
])
.config(function($stateProvider) {
$stateProvider
.state('app.example', {
url: '/example/examplecancha/:cancha',
views: {
'menuContent': {
templateUrl: 'scripts/example/examplecancha/example.html',
controller: 'InfoCanchaController as vm'
}
}
});
});
})();
你能告诉我为什么绑定没有显示任何内容? 谢谢!
答案 0 :(得分:0)
You have used controllerAs syntax.
ng-controller = "InfoCanchaController as ct"
// when you use controllerAs syntax, you are doing $scope.ct = vm = this;
{{ct.cancha.descripcion}}
//when you are injecting $scope in controller, you are attaching data to it directly.
//In this case it will work as, you are doing $scope.cancha.descripcion = something.
{{cancha.descripcion}}