Starting with Angular

Asked

Viewed 39 times

-2

I made a little source with controller in Angularjs and when executing I receive the error of the attached message.

inserir a descrição da imagem aqui

I don’t know where the error could be considering that this code is very simple.

Source:

<!DOCTYPE html>
<html lang="pt-br" ng-app>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Controllers</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular.min.js"></script>
</head>
<body>
    <div ng-controller="CtrlApp">
        <h1>{{nome}}</h1>
    </div>

</body>
<script type="text/javascript">
    var CtrlApp = function(){

    }
</script>
</html>
  • 1

    Ronaldo, please post the error text and not an image.

1 answer

0

There’s a lot of things wrong there.

First you need to create a module, then you need to register the controller in this module and, in order to be able to {{nome}} of view present something it is necessary to do the bind of nome in $scope.

angular.module('app', []).controller('CtrlApp', function($scope) {
  $scope.nome = 'LINQ';
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="CtrlApp">
  <h1>Meu nome é {{nome}}</h1>
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.