1. What is the output of result1 and result2 ?

var person = {'name' : 'sakshi', 'obj' :{'age': 24 }}, dest1 = {}, dest2 = {};
angular.copy(person, dest1);
angular.extend(person, dest2);
var result1 = person.obj === dest1.obj ? false : true;
var result2 = person.obj === dest2.obj ? false : true;

  1. true, true
  2. true, false
  3. false, true
  4. false, false
  5. None of the above

Ans: b

2. What is the output of host1 and host2?

// url → http://user:password@test.com:3000/#/path?param1=xyz¶m2=pqr
host1 = $location.host();
host2 = location.host;

  1. user:password@test.com, user:password@test.com:3000
  2. test.com:3000, user:password@test.com
  3. user:password@test.com, test.com:3000
  4. test.com, test.com:3000
  5. None of the above

Ans: d

3. What is the restriction type of below directive?

.directive('myDir', function() {
return {
restrict: 'AEC',
templateUrl: 'my-custom-template.html'
};
});

  1. matches either attribute or element or comment
  2. matches with attribute or element and class name
  3. matches with attribute and element or comment
  4. matches with attribute and element or class name
  5. None of the above

Ans: e

4. What are count values respectively when ‘Button One’ is clicked once and ‘Button Two’ clicked twice.

// index.html

<div ng-controller="MyController">
Root scope <b> MyEvent</b> count: {{count}}
<ul>
<li ng-controller="MyController">
<button ng-click="$emit('MyEvent')">Button Two
<li ng-controller="MyController">
Leaf scope <b> MyEvent</b> count: {{count}}
</li>
</ul>
</li>
</ul>
</div>

// script.js

angular.module('eventExample', [])
.controller('MyController', ['$scope', function($scope) {
$scope.count = 0;
$scope.$on('MyEvent', function() {
$scope.count++;
});
}]);

  1. 1, 2, 2
  2. 2, 2, 3
  3. 1, 3, 2
  4. 2, 1, 3
  5. 2, 2, 1

Ans: c

5. What <p> tag will display?

File Name : index.js

<div ng-controller="myController">
<input type="input" ng-model="myTitle" />
<br/> <p class="my-dir" title1="myTitle" title2="myTitle" title3="myTitle"></p>
</div>

File Name: script.js

var app = angular.module('app', []);
app.controller("myController", function ($scope) {
$scope.myTitle = "one";
});
app.directive("myDir", function () {
return {
replace: true,
restrict: 'C',
transclude: true,
scope: {
title1: "=",
title2: "@",
title3: "&"
},
template: "<div><p>Result: {{title1}} / {{title2}} / {{title3}}</p></div>"
};
});

  1. Result: one/one/one
  2. Result: one/myTitle/myTitle
  3. Result: myTitle/one/
  4. Result: one/myTitle/
  5. Result: one//

Ans: d

6. What is the output when transclude in directive takes values -1, 0 and 1?

File Name : index.htnl

<div ng-app='myApp'>
<div ng-controller='myCtrl'> <my-dir>
<span>User</span> </my-dir>
</div>
</div>

File Name : script.js

var app = angular.module('myApp', [])
app.controller('myCtrl', function ($scope) {
})
app.directive('myDir', function () {
return {
restrict: 'E',
transclude: true,
template: '<div ng-transclude>Hello </div>''
}
})

  1. User, Hello, User
  2. User, User, Hello User
  3. User, Hello User, User
  4. Hello User, Hello, Hello User
  5. Hello User, User, Hello

Ans: d

7. What is result of below line?


<div ng-non-bindable>{{1 + 2}}</div>

  1. empty
  2. 3
  3. 1+2
  4. {1 + 2}
  5. None of the above

Ans: e

8. What <p> tag will display?

File Name : index.html

<div ng-controller="MyCtrl"> <p>{{one}}, {{two}}, {{three}}, {{four}}</p> </div>

File Name : script.js

var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
function myFunction(fn, input) {
return (fn || angular.identity)(input);
};
$scope.one = myFunction(function(n) { return n + undefined; }, 10);
$scope.two = myFunction(function(n) { return n + true; }, 10);
$scope.three = myFunction(function(n) { return n + null; }, 10);
$scope.four = myFunction(false, 10);
}

  1. undefined, 10, 10, 10
  2. undefined, 11, 10, false
  3. null, 11, 10, 10
  4. null, 10, 10, 10
  5. None of the above

Ans: c

8. Output of $location.url(), $location.path() for given url?


given url http://test.com/#/some/path?param1=foo¶m2=bar

  1. http://test.com/, http://test.com/#/some/path
  2. http://test.com/#/some/path?param1=foo&param2=bar, http://test.com/#/some/path
  3. http://test.com/#/some/path, http://test.com/
  4. http://test.com/#/some/path, http://test.com/#/some/path?param1=foo&param2=bar
  5. None of the above

Ans: e

9. What <p> tag will display?

File Name: index.html

<div ng-controller="MyCtrl"> <p>{{one}}, {{two}}, {{three}}, {{four}}</p> </div>

File Name: script.js

var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
function myFunction(fn, input) {
return (fn || angular.identity)(input);
};
$scope.one = myFunction(function(n) { return n + undefined; }, 10);
$scope.two = myFunction(function(n) { return n + true; }, 10);
$scope.three = myFunction(function(n) { return n + null; }, 10);
$scope.four = myFunction(false, 10);
}

  1. undefined, 10, 10, 10
  2. undefined, 11, 10, false
  3. null, 11, 10, 10
  4. null, 10, 10, 10
  5. None of the above

Ans: c

10. What is the output?

File Name: index.html

<div ng-app="Test"> <div ng-controller="Controller"> <ng-pluralize count="people.length" offset="3" when="{ '0': 'Nothing is there.', '1': '{{person1}} is present.', '2': '{{person1}} and {{person2}} are present.', 'one': '{{person1}}, {{person2}} and one other person are present.', 'other': '{{person1}}, {{person2}} and {} other people are present.'}"> </ng-pluralize> </div> </div>

File Name: script.js

angular.module('Test', [])
.controller('Controller', ['$scope',function ($scope) {
$scope.people = ['one', 'two', true, false];
$scope.$watch('people', function () {
$scope.person1 = ($scope.people[0] ? $scope.people[0] : null);
$scope.person2 = ($scope.people[1] ? $scope.people[1] : null);
})
}
]);

  1. one is present
  2. one and two are present
  3. one, two and one other person are present.
  4. one, two and 2 other people are present
  5. None of the above

Ans: c

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.