Issue
I am preparing for an upcoming job interview and am trying to brush up on my Angular knowledge. I've been looking for Angular interview questions and came across this resource.
I'm hoping someone might be able to help me out with some of the code questions. For example, there is one question that asks to explain the following code:
<div ng-app="myApp" ng-controller="myCtrl">
<h1>{{ firstName + " " + lastName }}</h1>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.firstName= "John";
$scope.lastName= "Doe";
});
</script>
I think I understand the concepts here, but I'd love to get some more insight from someone who has experience with Angular.
Solution
I will try to clarify for you (but I think it's simple concepts on angularjs)
First, define angular.module with the name myApp , module is the same container that includes everything needed for the angular app (controller, directive, service,...). On HTML call ng-app="myApp" angular will find directive ng-app to run first
Second define app.controller with the name myCtrl , controller include directive $scope to save data and function
Third on HTML use interpolation e.g above {{ firstName + " " + lastName }} it will read the value of variables defined on controller. After running on the browser will show: John Doe
Answered By - Anonymus
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.