0

I have index.html as Master Page and indexController.js. index.html has a partial body

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

to load partial view, for example, login.html

The pure AngularJS project use semantic-ui. login.html has form login with implementing FormValidation of semantic-ui.

$(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;
        }
    })

});

In index.html, I have logic to hide or show menu

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

and indexController.js

$scope.authentication = authService.authentication;

How can I update information of indexController to show or hide menu on it?

2
  • You have to define your form function in contrroller. So you can update scope. Commented Oct 21, 2015 at 9:06
  • Hi @hurricane, I don't get your point? Commented Oct 21, 2015 at 9:07

1 Answer 1

1

Add your ('ui.form') function to indexController and then call it.

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;
        })
    });
  };
}]);

When you call $scope.loginControl() if it is succes your div will be opened.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank @hurricane, the big mistake of me is missing using indexController in index.html, so shame :(. But your code is look good.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.