我正在使用es6 AngularJS,并使用此代码声明了一个简单变量
export default class HomeCtrl {
constructor() {
'ngInject';
this.num = [1,2];
}
}
在我刚刚拥有的视图中
<span>{{ vm.num === undefined }}</span>
但它总是显示true
我正在使用此配置,所以我不确定导致问题的原因
$stateProvider
.state('app.home', {
url: '/',
controller: 'HomeCtrl',
contollerAs: 'vm',
template: homeView,
});
更新:
我发现它与AppCtrl冲突,我指定这是我的整个配置代码
export default angular.module('app', [
ngTouch,
ngSanitize,
uiRouter,
animations,
directives,
services,
controllers,
components,
])
.config(function($stateProvider, $locationProvider, $urlRouterProvider) {
'ngInject';
$stateProvider
.state('app', {
abstract: true,
controller: 'AppCtrl',
controllerAs: 'vm',
template: appView,
})
.state('app.home', {
url: '/',
controller: 'HomeCtrl',
contollerAs: 'vm',
template: homeView,
});
$urlRouterProvider.otherwise('/');
$locationProvider.html5Mode(true);
}).name;
当我在homeView.html中使用vm时,被调用的vm是AppCtrl的vm,它是我的父控制器
答案 0 :(得分:0)
找到了解决方法。像这样改变我的州提供者的角度问题解决了问题
while True:
game_choice = input('Do you want to play? ').lower()
if game_choice == 'yes' or 'y':
break
elif game_choice == 'no' or 'n':
sys.exit()
else:
print('Please answer only Yes/y or No/n')
continue