简体   繁体   中英

Angular.js ng-class visible if true from controller

I have Cordova app based on angular.js and these 2 documents:

app.html

<div ng-controller="MyAppCtrl as myApp" ng-class="myApp.isWindows() ? 'windows' : ''">

and app.controller

MyAppCtrl.$inject = ['$scope'];
function MyAppCtrl($scope) {
    var vm = this;
    vm.isWindows = isWindows;    
}

function isWindows() {
    return true;
}

I have to check something in isWindows function and if condition be true then return true - show class windows in html. But this is not working right now. I found a tutorial where was sample like this, but this is not working for me. Can you help me?

您只是使用了错误的ng-class语法,而是使用以下语法:

<div ng-controller="MyAppCtrl as myApp" ng-class="{windows: myApp.isWindows()}">...</div>

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