我有基于 angular.js 的 Cordova 应用程序和这两个文档:
app.html
<div ng-controller="MyAppCtrl as myApp" ng-class="myApp.isWindows() ? 'windows' : ''">
和app.controller
MyAppCtrl.$inject = ['$scope'];
function MyAppCtrl($scope) {
var vm = this;
vm.isWindows = isWindows;
}
function isWindows() {
return true;
}
我必须检查 isWindows
函数中的某些内容,如果条件为 true
,则返回 true
- 显示类 windows
> 在 html 中。但这现在不起作用。我找到了一个教程,其中有这样的示例,但这对我不起作用。你能帮我吗?
最佳答案
你只是搞错了ng-class
语法,请改用此语法:
<div ng-controller="MyAppCtrl as myApp" ng-class="{windows: myApp.isWindows()}">...</div>
关于javascript - Angular.js ng-class 如果 true 从 Controller 可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33674943/