0

Following online examples, I have something like this in login.html:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js"></script>
<script type="text/javascript" src="app/app.login.js"></script>

<div id="loginButton" ng-app="loginButton" ng-controller="loginControl">
    <button ng-click="enterSite()">
        Enter
    </button>
</div>

Then in app.login.js:

var appButton = angular.module("loginButton", []);

appButton.controller("loginControl", ["$scope", "$window", function($scope,  $window){
    $scope.enterSite = function(){
        $window.location.href = "../index.html";        
    }
}]);

However, it does not redirect to index.html when I press the button. There are no errors in the browser's log. I've copied most of the format from working examples, so I cannot find why it does not work for me.

Any tips would be appreciated.

1 Answer 1

1

Your code works as it is without any change.

Look in your local system if you see any javascript related issues or script isn't loading from ajax.googleapis.com.

Check if you have linked your login.js properly

var appButton = angular.module("loginButton", []);

appButton.controller("loginControl", ["$scope", "$window", function($scope,  $window){
    $scope.enterSite = function(){
        $window.location.href = "../index.html";        
    }
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js"></script>
<script type="text/javascript" src="app/app.login.js"></script>

<div id="loginButton" ng-app="loginButton" ng-controller="loginControl">
    <button ng-click="enterSite()">
        Enter
    </button>
</div>

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

2 Comments

You're right, the excerpt I provided worked. However, I embarrassingly used 2 ng-app in login.html (after a bunch of research, I only recently found out you can only use one), so I guess it just ignored both. Thanks for informing me the error wasn't in what I provided.
@Yifan It happens :). For loading the second application you have to manually bootstrap it through code.

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.