Summary of small pits and skills encountered by AngularJS

  • 2021-06-28 07:10:28
  • OfStack

1. templateURL and routing and the like run under web and server.

2. Set the template replace to true, and there should be corresponding labels in the template, otherwise no data will appear.

After version 3. 1.2, the ngRoute module is independent.

4. An error occurs if an empty controller is not defined.

5. The link parameters of Directive are sequential: scope, element, attrs, ctrl

6. ng-repeat cannot cycle repeating objects. hack: ng-repeat = "thing in things track by $id ($index)"

7. Try to update the attributes of variables instead of the individual variables themselves.

8. Note that ng-repeat, ng-controller, etc. create independent scopes.

9. When jquery is loaded, use jquery, otherwise use built-in jqlite. all element references in Angular are always wrapped with jQuery or jqLite; they are never raw DOM references.

10. Uncaught Error: [$location: ihshprfx] A tag not removed < a href="#" ng-click="someMethod();" > < /a >

11. Error: listen EACCES When under linux, this error occurs because of the port you are listening on, and here mine is 33. Change it to a large number of ports such as 8080 or 3030. There is a provision that these ports are preferably larger than 1024.

12. select cannot be displayed without ng-model. Similarly, when encountering a document that can't show the best view, what is missing.

Supplement: When the source of ng-options does not match the writing, all selections will occur, as follows:

var a = [{"id": 1, "name": "Ryan"}...], ng-options = "item. i as item. name for item in a"//i is different from id

----------------------------------------------------------------------------------------

13. ng-bind-html-unsafe has been removed, either using the ['ngSanitize'] module or using the $sce service

From stackoverflow

You indicated that you're using Angular 1.2.0... as one of the other comments indicated, ng-bind-html-unsafe has been deprecated.

Instead, you'll want to do something like this:

<div ng-bind-html="preview_data.preview.embed.htmlSafe"></div>

In your controller, inject the $sce service, and mark the HTML as "trusted":

myApp.controller('myCtrl', ['$scope', '$sce', function($scope, $sce) {
  // ...
  $scope.preview_data.preview.embed.htmlSafe =
     $sce.trustAsHtml(preview_data.preview.embed.html);
}

Note that you'll want to be using 1.2.0-rc3 or newer. (They fixed a bug in rc3 that prevented "watchers" from working properly on trusted HTML.)


Related articles: