1

Couldn't get start with angularjs, need help.

My app.js

var app = angular.module('cartApp', ['ui.router']);

app.controller('dashboardCtrl', function() {

    var dash = this;
    dash.something = "something";

});

index.html

<!DOCTYPE html>
<html lang="en" ng-app="cartApp">
<head>
    <meta charset="UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>


    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.3.1/angular-ui-router.js"></script>


</head>
<body ng-controller="dashboardCtrl">{{something}}

/body>
</html>

I think I messed up but don't know where is it.

4
  • Hi, could you please post the full error, normally with injection errors it will tell you which module it had problems injecting. Commented Sep 2, 2016 at 15:26
  • You should correct your script tag starting with < like <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.3.1/angular-ui-router.js"></script>, Also refer app.js file on index.html Commented Sep 2, 2016 at 15:26
  • @GeorgeLee oh it doesn't have error just the {{something}} is not printing. Commented Sep 2, 2016 at 15:38
  • @PankajParkar that's just a typo Commented Sep 2, 2016 at 15:38

3 Answers 3

1

You have all your bindings available inside controller context(this), so you should use controllerAs pattern to get binding available in this on the view. There you will be using controller alias inside ng-controller directive & you should use dash to get controller binding.

<body ng-controller="dashboardCtrl as dash">
   {{dash.something}}
</body>

Also make sure you have referred app.js on the page.

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

Comments

0

could you try in controller?

 app.controller('dashboardCtrl', function($scope) {

    $scope.something = "something";

});

Comments

0

For future references, I suggest to follow this great tip.

It's very useful because provide better readability and avoid make these kinds of mistakes.

Comments

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.