Definition of promo in coding please


#1

"Likewise, any new properties attached to $scope will become available to use in the view. In the controller, attach promo to $scope, and set its value to your own string. Please im struggling to figure out what they mean by this and what value they are talking about? Would greatly appreciate the help


#2

When we say $scope.[something] we are "attaching" a property to $scope. When we attach things to $scope we can use them in the view (the HTML file)

MyController.js

var app = angular.module("myApp", []);
app.controller('MyController', ['$scope', function($scope) { 
  $scope.promo = 'Here is my random string';
}]);

Within the double curly braces {{promo}} we are accessing the $scope.promo value we set in the controller. It should print out "Here is my random string"

view.html

<body ng-app="myApp">
     <div ng-controller="MyController">
        {{promo}}
    </div>
</body

#3

3 posts were split to a new topic: Attaching a new property to scope


#4