Ayyan Alvi
Ayyan Alvi

Reputation: 821

simply trying to show value when it's entered in input field (angular js)

i am very new to laravel and angular js. The thing i want to do is to display display the span which inner value will be placeholder and there will be input field when user will enter any value then instead of that place holder new value of text field will be written there.

<!DOCTYPE html>
<html>
 <head>
  <script data-require="[email protected]" data-semver="1.2.0-rc2"   src="http://code.angularjs.org/1.2.0-rc.2/angular.js"></script>
  <link rel="stylesheet" href="style.css" />
  <script src="script.js"></script>
  <script>
   function Controller($scope) {
     $scope.data = {
       company_name : ''
      };

     $scope.isEmptyCompany = function () {
        return company_name === ''; 
      }
  }
</script>
</head>
  <body>
   <div ng-app ng-controller="Controller">
      <input type="text" ng-model="data.company_name"/>
      <div class="company_name">
          <h1 class="left">
              <span ng-if="data.company_name === ''">
                  Placeholder
              </span>
              <span ng-if="data.company_name!==''">
                  {{data.company_name}}
              </span>
          </h1>
      </div>
     </div>
   </body>
</html>

it is displaying this error i don't know why it's happening

Use of undefined constant data - assumed 'data' (View: C:\xampp\htdocs\laravel\app\views\user\user_admin_info.blade.php)

Upvotes: 2

Views: 1122

Answers (2)

Homo Sapien
Homo Sapien

Reputation: 300

One solution is to precede the curly braces with @ symbol like described by @Ben. But when working with angular (IMHO) I think it's better to simply use .php views instead of .blade.php views because otherwise you would have to include @ everywhere in your views. And secondly in angular specific views, well there isn't always a whole lot of server side templating going on. Even if we need something we can use php's native <?php ?> templating.

Upvotes: 2

Ben Claar
Ben Claar

Reputation: 3415

Laravel is processing your {{ tag }} instead of Angular. You need to tell Laravel to ignore your Angular tags:

@{{data.company_name}}

For more information, see "Blade & JavaScript Frameworks" under Displaying Data.

Upvotes: 1

Related Questions