1

I am trying to set default value of username( $scope.userName) and password( $scope.password),I have tried with ng-init but its not working, but its not working here is my code :

APP.directive('loginUser', ['$http','$interval','$rootScope','$timeout', function ($http,$interval,$rootScope,$timeout) {
function link($scope, element, attrs) {

    $scope.userName = 'Ali';
    $scope.password = 'pass';

}

return {
    link: link
};


}]);

here is my html

<div class="modal-body" login-user  >

    <form class="custom-form" name="loginForm" ng-submit="loginSubmit()" novalidate>

        <label class="museo_sans500" for="email">Nome utente o indirizzo email</label>
        <input type="text" class="form-control museo_sans300" id="userName" placeholder="Nome utente o indirizzo email" ng-init="userName='<?php echo "Yesss" ?>'"   name="UserName" minlength="5" ng-model="userName" required="required">

      <div class="form-group">
        <label class="museo_sans500" for="password">Password</label>
        <input type="password" class="form-control museo_sans300" id="password" placeholder="Password" name="password"  minlength="5" ng-model="password"  required="required">
      </div>
      <div class="form-group">
        <label class="museo_sans700"><a href="javascript:void(0)"  ng-click="forgotPasswordShow()">Hai dimenticato la password?</a></label>
        <label class="museo_sans700" style="margin-left: 30px;"><input type="checkbox" ng-model="rememberMe" name="remember-me"> Ricordami</label>
      </div>
      <button type="submit" class="btn play-now museo_sans500 m-t-20px login-btn"  ng-disabled="loginForm.$invalid">ENTRA</button>
      <div class="or museo_sans500">oppure</div>

    </form>
  </div>

Thanks in advance

2 Answers 2

1

instead of ng-init you should assign default value in your controller/directive and in input field just use ng-model.

In directive :

$scope.userName = 'Ali'; // default name

in html:

<input type="text" class="form-control" id="userName" placeholder="name" name="UserName" ng-model="userName" required="required">

PLUNKER DEMO

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

6 Comments

You can see in code there is value direct assigning to ng-model but that's not working
you may facing another issue. I added plunker demo you can visit this
Yes bro that's why I am asking ,
in your browser console shown any error? and are you using module name in html root element?
I saw your link. can you try by change your variable name $scope.userName and change ng-model = "changedName". may be overwrite by another controller or directive that used in same page or parent page. because of when click on enter button then get entered value.
|
1

For the value of the attribute placeholder use:

<input type="password" class="form-control museo_sans300" id="password" placeholder="{{password}}" name="password"  minlength="5" ng-model="password"  required="required">

Pretty sure this should work. Let me know how if you continue to have problems.

1 Comment

I want to use value not a placeholder bro

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.