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

24
Q

angular: Services must

A

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

25
angular: A common service is
a rest api connector
26
angular: inside of a services callback function, the "this" method refers to
the service itself
27
angular: To create a service with the $http provider that gets data, type
.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
angular: ng-repeat automatically gives each item a
$index in their scope which you can pass to an ng-click function like ng-click="functionName($index)"
29
angular: To onclick change the value of a variable to it's opposite, type
ng-click="varName = !varName"
30
angular: To hide something based on if a variable returns true, type
ng-hide="varName"
31
angular: To add fake data to your app for testing,
assign an array of javascript objects to a variable in the $scope of one of the controllers
32
angular: To change the value of a variable when a user clicks outside of the input they are using, type
ng-blur="varName = value"
33
angular: To apply a class based on whether or not a variable returns true, type
ng-class="{ 'class-name': varName, 'class-name': varName }"
34
angular: To watch for when the value of an input changes and then run a function, type
ng-change="functionName()"
35
angular: To add a new object to an array already in $scope, type
$scope.arrayName.push( {"key": "value"} )
36
angular: To remove an object from an array already in $scope, type
$scope.arrayName.splice(indexOfObject, 1)
37
angular: To hide an element until it is fully rendered so you do not see mustaches
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
angular: To limit the number of items ng-repeat renders, type
| limitTo:10
39
angular: To sort ng-repeat according to one field, type
| orderBy: 'fieldName': false | note: false refers to reverse ordering or not
40
angular: To run a function on page load, type
into the controller $window.onload = function(e) { ... } note: Must pass in $window object into the controller
41
python: To create an http server, type
python -m http.server
42
json: Json objects
must have quotes around key names
43
angular: To create an if else statement in the template
Create two divs, each with ng-if="varName == 10" ng-if="varName != 10"
44
angular: To import angular route, type
-script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular-route.js">
45
angular: To set where in the index.html angular will inject the view, type
-div ng-view>-/div>
46
angular: To add routes to angular, type
``` angular.module("negatizer", ['ngRoute']) .config(function ($routeProvider) { $routeProvider .when("/", { controller: "nameCtrl", templateUrl: "partials/template.html" }) .otherwise({ redirectTo: "/path/" }); }); ```
47
http: to set a cookie on a browser without javascript
Use the Set Cookie http response header
48
angular: You should use $scope.$apply(function (){ ... }) if
You are updating your variables after a full turn of javascript rendering so that angular knows to update the ui.
49
angular: Putting your function inside rather than before $scope.$apply(function (){ ... }) is preferable because
$apply puts your code in a try catch block so errors are caught within angular.
50
angular: If sending a parameter to a service, send it
through this.methodName, not the anonymous function of the service
51
angular: new FormData() must be
capitalized
52
angular: To create a service that posts a form, type
.service("postFormData", function($http){ this.postFormData = function(data, callback){ $http.post("endpoint.com/", data).then(callback) } })
53
js: To add a file in a form field to a FormData() object, type
``` var form = new FormData() form.append("file", formElement.files[0], "file.csv") ```
54
angular: When using angular inside a django app
put the index.html into base.html and then put the rest of the app inside the static folder.
55
angular: Import that app.js into the page
last