خرید بک لینک

Vote count: 0

I'm trying to get my sidebar ng-class to correctly see when the AppState service's state has changed. I change it be calling $scope.appState.toggleTips() from the one controller which should (and does) update the AppState.state.showTips property.

What's strange is at this point BOTH the {'show-prism': appState.state.showPrism} and {'show-tips': appState.state.showTips} should be updated as they are both bound to the service AppState's values. They appear to be updated when I log them but the VIEW does not apply the 'show-tips' class to the html even though my console log shows appState.state.showTips to be true. However, it DOES add 'show-prism' to the view and it also is true. What is going on? Why isn't it apply show-tips when the controller value is true?

The div for 'show-tips' will eventually update itself with the ng-class after I run the header's togglePrism() function, but I always have to seem to run the togglePrism() function again to see it update. I need it to apply immediately, as it's already doing for 'show-prism'.

/**
 * AppState Service
 * @namespace Services
 */

angular
    .module('sharepoint-angular-starter')
    .service('AppState', AppState);

function AppState() {
    this.state = {
        showPrism: false,
        showTips: false
    };

    this.togglePrism = function () {
        this.state.showPrism = !this.state.showPrism;
    };

    this.toggleTips = function () {
        console.log(this.state);
        this.state.showTips = !this.state.showTips;
        console.log(this.state);
    };

    this.getState = function () {
        retu this.state;
    };
}

/** Index.html **/
<div ng-app="sharepoint-angular-starter" id="ngApp">
            <div id="header" ui-view="header"></div>
            <div id="content" ui-view="content" ng-class="{'prism-showing': appState.state.showPrism}"></div>
            <div id="sidebar" ui-view="sidebar"></div>
            <div id="footer" ui-view="footer"></div>
    </div>

/**
 * Header Controller
 * @namespace Controllers
 */
angular
    .module('sharepoint-angular-starter')
    .controller('HeaderCtrl', HeaderCtrl);

function HeaderCtrl($scope, AppState) {
    $scope.message = 'Here is your first message';
    $scope.appState = AppState;
}

/** header.html **/
<div class="sidebar-toggle">
  <div class="current-user">
      <img src="http://lh5.googleusercontent.com/-CA8-IvI1W3s/AAAAAAAAAAI/AAAAAAAAAAA/AMW9Ige6_gxZd4VtSCjF8Gk8eP1V-6gs-A/s32-c-mo/photo.jpg" />
  </div>
  <div class="toggle-switch" ng-click="appState.togglePrism()">
      <i class="toggle-icon fa fa-chevron-circle-left fa-2x" ng-class="{'fa-chevron-circle-left': !appState.state.showPrism,'fa-chevron-circle-right': appState.state.showPrism}"></i>
  </div>
</div>

function ContentCtrl($scope, AppState) {

$scope.appState = AppState;

var simplemde = new SimpleMDE({
    element: document.getElementById("simplemde"),
    toolbar: [
    {
        name: "markdownTips",
        className: "fa fa-question-circle",
        action: getMarkdownHelp,
        title: "Markdown Tips"
    }]
});

function getMarkdownHelp(editor) {
    console.log('controller');
    console.log($scope.appState);
    $scope.appState.toggleTips();
    console.log($scope.appState);
    console.log(AppState);
}

$scope.message = 'Here is your first message';

}

/**
 * Sidebar Controller
 * @namespace Controllers
 */
angular
    .module('sharepoint-angular-starter')
    .controller('SidebarCtrl', SidebarCtrl);

function SidebarCtrl($scope, AppState) {
    $scope.message = 'Here is your first message';
    $scope.appState = AppState;
}

/** sidebar.html **/
<div class="sidebar-container" ng-class="{'show-prism': appState.state.showPrism}">
    <ul class="sidebar-header">
        <li>Nav</li>
        <li>Comments</li>
        <li>Info</li>
    </ul>
    <div class="sidebar-body">
        Body stuff here {{message}}
    </div>
    <div class="markdown-tips" ng-class="{'show-tips': appState.state.showTips}">
        <div ng-include="'sidebar/markdownTips.html'"></div>
    </div>
</div>
asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 18 ارديبهشت 1395 ساعت: 20:39

صفحه بندی