2015-10-21 87 views
0

我有index.html作爲主頁面和indexController.js。 index.html的具有部分體通過jQuery調用控制器的AngularJS函數來更新主控制器

<div ng-view=""></div> 

加載局部視圖,例如,login.html的

純AngularJS項目使用語義UI。 login.html具有表單登錄並實現了語義UI的FormValidation。

$(document).ready(function() { 
$('.ui.form') 
    .form({ 
     // some setting.... 
     onSuccess: function (event, fields) { 
      var scope = angular.element($('#loginForm')).scope(); 

      scope.$apply(function() { 
       scope.login(); 
      }); 

      return false; 
     } 
    }) 

});

index.html中,我有邏輯隱藏或者顯示菜單

<a class="ui item" ng-hide="!authentication.isAuth" href="#/assets">Asset</a> 

和indexController.js

$scope.authentication = authService.authentication; 

如何更新它indexController的信息顯示或隱藏菜單?

+0

你必須在控制器中定義你的表單功能。所以你可以更新範圍。 – hurricane

+0

嗨@hurricane,我不明白你的意思嗎? –

回答

1

將你的('ui.form')函數添加到indexController然後調用它。

angular.module('scopeExample', []) 
.controller('indexController ', ['$scope', function($scope) { 
    $scope.authentication.isAuth = false; 

    $scope.loginControl = function() { 
    $('.ui.form') 
     .form({ 
      onSuccess: function (event, fields) { 
       $scope.authentication.isAuth = true; 
     }) 
    }); 
    }; 
}]); 

當您打電話給$scope.loginControl()如果它成功,您的div將被打開。

+0

感謝@hurricane,我的大錯誤是在index.html中使用indexController時丟失了,所以慚愧:(。但是你的代碼看起來不錯。 –