title: Creating new function in angularjs controller won't work
body: <p>When creating new function in angularjs controller and assign it to button with ng-click and function is simple,</p>
  
  
  
  <pre><code>function toLogin() {
      console.log("Entered function");
      $state.go('login');
  }
  </code></pre>
  
  <p>I tried with $scope and still does not work. 
  this is my controller: </p>
  
  <pre><code>'use strict';
  </code></pre>
  
  <p>angular.module('crudApp').controller('UserController',
      ['UserService', '$scope','$state',   function( UserService, $scope, $state) {</p>
  
  <pre><code>    var self = this;
      self.user = {};
      self.users=[];
      self.user.enabled = false;
      self.user.confirmationToken = '';
      self.loggedUser = null;
      self.submit = submit;
      self.getAllUsers = getAllUsers;
      self.createUser = createUser;
      self.updateUser = updateUser;
      self.removeUser = removeUser;
      self.editUser = editUser;
      self.reset = reset;
      self.firstNamePattern=/^[A-Z][a-z]*\S$/;
      self.lastNamePattern=/^[A-Z][a-z]*\S$/;
      self.userNamePattern= /^\S*$/;
      self.passwordPattern = /^\S*$/;
      self.phonePattern = /^[0-9]+\S$/;
      self.successMessage = '';
      self.errorMessage = '';
      self.done = false;
  
      self.onlyIntegers = /^\d+$/;
      self.onlyNumbers = /^\d+([,.]\d+)?$/;
      function toLogin() {
          console.log('Entered function');
         // $state.go('login');
      }
      function submit() {
          console.log('Submitting');
          if (self.user.id === undefined || self.user.id === null) {
              console.log('Saving New User', self.user);
              createUser(self.user);
          } else {
              updateUser(self.user, self.user.id);
              console.log('User updated with id ', self.user.id);
          }
      }
      $scope.moje = function () {
          console.log('Submitting');
          if (self.user.id === undefined || self.user.id === null) {
              console.log('Saving New User', self.user);
              createUser(self.user);
          } else {
              updateUser(self.user, self.user.id);
              console.log('User updated with id ', self.user.id);
          }
      }
  
      function createUser(user) {
          console.log('About to create user');
          UserService.createUser(user)
              .then(
                  function (response) {
                      console.log('User created successfully');
                      self.successMessage = 'User created successfully';
                      self.errorMessage='';
                      self.done = true;
                      self.user={};
                      $scope.registerForm.$setPristine();
                      $scope.registerForm.$setUntouched();
                     // $state.reload();
  
                  },
                  function (errResponse) {
                      console.error('Error while creating User');
                      self.errorMessage = 'Error while creating User: ' + errResponse.data.errorMessage;
                      self.successMessage='';
                  }
              );
      }
  
  
      function updateUser(user, id){
          console.log('About to update user');
          UserService.updateUser(user, id)
              .then(
                  function (response){
                      console.log('User updated successfully');
                      self.successMessage='User updated successfully';
                      self.errorMessage='';
                      self.done = true;
                      $scope.myForm.$setPristine();
                  },
                  function(errResponse){
                      console.error('Error while updating User');
                      self.errorMessage='Error while updating User '+errResponse.data;
                      self.successMessage='';
                  }
              );
      }
  
  
      function removeUser(id){
          console.log('About to remove User with id '+id);
          UserService.removeUser(id)
              .then(
                  function(){
                      console.log('User '+id + ' removed successfully');
                  },
                  function(errResponse){
                      console.error('Error while removing user '+id +', Error :'+errResponse.data);
                  }
              );
      }
  
  
      function getAllUsers(){
          return UserService.getAllUsers();
      }
  
      function editUser(id) {
          self.successMessage='';
          self.errorMessage='';
          UserService.getUser(id).then(
              function (user) {
                  self.user = user;
              },
              function (errResponse) {
                  console.error('Error while removing user ' + id + ', Error :' + errResponse.data);
              }
          );
      }
      function reset(){
          self.successMessage='';
          self.errorMessage='';
          self.user={};
          $scope.myForm.$setPristine(); //reset Form
      }
  }
  
  
  ]);
  </code></pre>
  
  <p>And and I using ui-routing and this is where I assign controller to my view:</p>
  
  <pre><code>}).state('success',{
                  url: '/success',
                  templateUrl: 'partials/successMessage',
                  controller: 'UserController',
                  controllerAs: 'sCtrl'
              });
  </code></pre>
  
  <p>And the ftl part of code is here: </p>
  
  <pre><code>&lt;button type="button" ng-click='sCtrl.toLogin()' class="btn btn-primary"&gt;Login&lt;/button&gt; 
  </code></pre>
  
  <p>It won't even print to console, but when assigning older function it works perfectly, although it is much more complicated. Ps. Sorry for bad clarification at first, I am new to community and still learning a proper way to ask question.</p>