1

This is the fist angular app that I try to make ,let's see

var app = angular.module('miApp', []);

app.controller('CochesController', function($scope) {
   $scope.coche ={
    marca:"Renault",
    modelo:"Clio",
  };

  $scope.nombreCompleto = function(){
    var x = $scope.coche;
    return x.marca+" "+x.modelo;
  };
})

and the view

<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link href="style.css" rel="stylesheet" />
    <script data-semver="1.4.8" src="https://code.angularjs.org/1.4.8/angular.js" data-require="[email protected]"></script>
    <script data-require="[email protected]" data-semver="1.4.8" src="script.js"></script>
    <script src="app.js"></script>
  </head>

  <body ng-app="miApp" ng-controller="CochesController">
    <p>{{coche.nombreCompleto()}}</p>
  </body>

</html>

I can use the attributes marca and modelo but I can't use the function ¿whats is wrong?

1 Answer 1

1

You could directly call the method available inside a controller scope by methodName, It should be like below,

<p>{{nombreCompleto()}}</p>
Sign up to request clarification or add additional context in comments.

3 Comments

It works, thank you , I t tried with ´{{coche.marca}}´ and it worked and I thought that it was the same with functions.
@AFS Glad to help you..Thanks :)
As a side note, I'd also suggest you look in to the 'controller as' syntax that is recommended as an alternative to assigning everything to $scope. toddmotto.com/digging-into-angulars-controller-as-syntax

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.