angular Flashcards

1
Q

angular: To set the scope of an app into the html

A

add the html attribute ng-app=”appName” to the html tag or whatever div you want angular to run in

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

angular: To render a variable into the html, type

A

{{ myVar }}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

angular: To create a variable named varName that becomes the value of whatever is in an input field and vice versa, type

A

-input type= “text” ng-model=”varName”>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

angular: The file that contains all of the functions you want to run is called

A

controllers.js

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

angular: The $scope argument to a controller function

A

is an object that gives you access to the variable namespace inside the tags its declared in.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

angular: To change the value of a variable inside the template using a controller, type

A

$scope.varName = “string”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

angular: To loop over all the items of a list and render them as list items, type

A

-li ng-repeat=”item in listVar”> {{ item }} -/li>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

angular: When rendering an images source from an angular variable, you must

A

use ng-src instead of src so that the browser does not try to fetch src={{ myVar }} in seconds before angular compiles in the correct value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

angular: To make a url that will not reload the page, but where the change will be listened to by angular, type

A

href=”#/path”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

angular: The file structure of an angular app is

A

index.html
scripts
vendor
styles

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

angular: To make the app.js file the real app

A

start the file with

angular. module(“projectName”, [])
note: [] is mandatory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

angular: The [ ] in angular.module(“projectName”, []) is for

A

listing dependencies

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

angular: directives are

A

custom tags or attributes inside tags that render the return of the directives function inside of them

e. g.
- my-directive>-/my-directive> or
- tag my-directive>-/tag>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

angular: files that contain directives should be

A

imported into the html template after the app script

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

angular: To create a directive function that can only be called as an element/tag, type

A
angular.module("appName")
.directive("directiveName", function(){
  return {
    template: "string",
    restrict: "E"
  }
})
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

angular: directive names should be written

A

as camel case in scripts, but lower case with dashes between words.
e.g.
myDirective would be
-my-directive>-/my-directive>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

angular: To make a directive only work as a tag and not an attribute type

A
angular.module("appName")
.directive("directiveName", function(){
  return {
    template: "string",
    restrict: "E"
  }
})
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

angular: The return of a directive can also be a

A

function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

angular: The naming convention for angular controller is

A

nameCtrl

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

angular: To make a controller, type

A
angular.module("nameCtrl"), 
.controller("nameCtrl", function($scope){
  $scope.functionName = function() {
    ...
  }
})
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

angular: To set the controller into some tags

A

add the attribute ng-controller=”controllerName” into the chosen tags

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

angular: To run a function from a controller on click of an html element

A

add the attribute ng-click=”functionName()”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

angular: A function or method that is available to many controllers is called a

A

service

24
Q

angular: Services must

A

be set as a dependency in the controllers that want to use them

25
Q

angular: A common service is

A

a rest api connector

26
Q

angular: inside of a services callback function, the “this” method refers to

A

the service itself

27
Q

angular: To create a service with the $http provider that gets data, type

A

.controller(“nameCtrl”, function($scope){
nameService.methodName(function(response) {
$scope.varName = response.data
})
})

.service("nameService", function($http){
  this.methodName = function(callback) {
    $http.get("url.com").then(callback)
  }
})
28
Q

angular: ng-repeat automatically gives each item a

A

$index in their scope which you can pass to an ng-click function like ng-click=”functionName($index)”

29
Q

angular: To onclick change the value of a variable to it’s opposite, type

A

ng-click=”varName = !varName”

30
Q

angular: To hide something based on if a variable returns true, type

A

ng-hide=”varName”

31
Q

angular: To add fake data to your app for testing,

A

assign an array of javascript objects to a variable in the $scope of one of the controllers

32
Q

angular: To change the value of a variable when a user clicks outside of the input they are using, type

A

ng-blur=”varName = value”

33
Q

angular: To apply a class based on whether or not a variable returns true, type

A

ng-class=”{ ‘class-name’: varName, ‘class-name’: varName }”

34
Q

angular: To watch for when the value of an input changes and then run a function, type

A

ng-change=”functionName()”

35
Q

angular: To add a new object to an array already in $scope, type

A

$scope.arrayName.push( {“key”: “value”} )

36
Q

angular: To remove an object from an array already in $scope, type

A

$scope.arrayName.splice(indexOfObject, 1)

37
Q

angular: To hide an element until it is fully rendered so you do not see mustaches

A

add to css
[ng:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
display: none !important;
}

add attribute
ng-cloak

38
Q

angular: To limit the number of items ng-repeat renders, type

A

limitTo:10

39
Q

angular: To sort ng-repeat according to one field, type

A

| note: false refers to reverse ordering or not

orderBy: ‘fieldName’: false

40
Q

angular: To run a function on page load, type

A

into the controller

$window.onload = function(e) {

}

note: Must pass in $window object into the controller

41
Q

python: To create an http server, type

A

python -m http.server

42
Q

json: Json objects

A

must have quotes around key names

43
Q

angular: To create an if else statement in the template

A

Create two divs, each with

ng-if=”varName == 10”

ng-if=”varName != 10”

44
Q

angular: To import angular route, type

A

-script src=”https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular-route.js”>

45
Q

angular: To set where in the index.html angular will inject the view, type

A

-div ng-view>-/div>

46
Q

angular: To add routes to angular, type

A
angular.module("negatizer", ['ngRoute'])
.config(function ($routeProvider) {
    $routeProvider
    .when("/", {
        controller: "nameCtrl",
        templateUrl: "partials/template.html"
    })
    .otherwise({
        redirectTo: "/path/"
    });
});
47
Q

http: to set a cookie on a browser without javascript

A

Use the Set Cookie http response header

48
Q

angular: You should use $scope.$apply(function (){ … }) if

A

You are updating your variables after a full turn of javascript rendering so that angular knows to update the ui.

49
Q

angular: Putting your function inside rather than before $scope.$apply(function (){ … }) is preferable because

A

$apply puts your code in a try catch block so errors are caught within angular.

50
Q

angular: If sending a parameter to a service, send it

A

through this.methodName, not the anonymous function of the service

51
Q

angular: new FormData() must be

A

capitalized

52
Q

angular: To create a service that posts a form, type

A

.service(“postFormData”, function($http){
this.postFormData = function(data, callback){
$http.post(“endpoint.com/”, data).then(callback)
}
})

53
Q

js: To add a file in a form field to a FormData() object, type

A
var form = new FormData()
form.append("file", formElement.files[0], "file.csv")
54
Q

angular: When using angular inside a django app

A

put the index.html into base.html and then put the rest of the app inside the static folder.

55
Q

angular: Import that app.js into the page

A

last