JavaScript Angular JS : Controller properties not shown in html

I'm new to Angular JS. Sorry for this simple question.

I have learnt something from this tutorial: http://courseware.codeschool.com/shaping-up-with-angular-js/Slides/level01-05.pdf

And I have tried an example. This is not working. http://jsfiddle.net/89wfv/1/

HTML:

<html ng-app="main">
    <body>
    <div ng-controller="con">

        <div>{{con.desc}}</div>
        <input type='button' ng-click='getDesc();' value='Get name' />
    </div>
    </body>
</html>

Script

(function() {

    var app = angular.module("main", []);

    app.controller("con", function() {

        this.desc = "test description";

        this.getDesc = function() {
            alert(this.desc);
        }

    });

})();

Problem is showing description in div and alert description by click.

Thanks in advance.

Answer:1

you forgot controller as something

<div ng-controller="con as ctrl">

    <div>{{ctrl.desc}}</div>
    <input type='button' ng-click='ctrl.getDesc();' value='Get name' />
</div>

take a look at the guide instead :

https://docs.angularjs.org/guide/controller

works:

http://jsfiddle.net/pYh89/

you didnt load angular correctly and add several syntax errors.

var app = angular.module("main", []);
app.controller("con", function () {

    this.name = 'foo';

    this.getName = function () {
        alert("foo");
    };

});
Answer:2

Angular JS is missing in your code please include it after downloading it.

<script src="angular.js"></script>

You can also use online version.

Answer:3

In this code, I want to display show more link, after 3 buttons: I know, how to display show more button after x words, but how to display show more link after buttons? This is my code to display ...

In this code, I want to display show more link, after 3 buttons: I know, how to display show more button after x words, but how to display show more link after buttons? This is my code to display ...

  1. show read more in jquery
  2. show read more in php
  3. show read more in wordpress
  4. today show read more today
  5. show hide read more javascript
  6. wordpress show read more link
  7. how to show read more in html
  8. javascript hide/show read more for long text
  9. how to show read more link in wordpress post
  10. how to show read more in textview in android
  11. read more show less
  12. read more show hide text
  13. read more show less jquery
  14. read more show less javascript
  15. read more show hide jquery
  16. read more show less css
  17. read more show less bootstrap
  18. read more show hide div
  19. wp-show-posts-read-more
  20. read more. show less. reply

I'm using Rails 4.1.1 and Ruby 2.1.2p95. I am using Slim as my HTML templating language (similar to HAML). I'm using Thin as my Rack server. I am trying to make a fully-AJAX application (one of my ...

I'm using Rails 4.1.1 and Ruby 2.1.2p95. I am using Slim as my HTML templating language (similar to HAML). I'm using Thin as my Rack server. I am trying to make a fully-AJAX application (one of my ...

  1. rails default text
  2. rails textarea default value
  3. rails text default value
  4. rails select default text
  5. rails default value text_field

I want to access the refs from the render function, and set it to the state. Here is my code: export default class App extends Component { constructor(props) { super(); ...

I want to access the refs from the render function, and set it to the state. Here is my code: export default class App extends Component { constructor(props) { super(); ...

Someone told me that there's !< and !> in JavaScript. I tried it but it didn't work. Is there something like this in JavaScript? If not in JavaScript, is it there in any other language?

Someone told me that there's !< and !> in JavaScript. I tried it but it didn't work. Is there something like this in JavaScript? If not in JavaScript, is it there in any other language?

  1. javascript there was an error processing the request
  2. is-there javascript
  3. in javascript there are objects of