• angular笔记


    1:动态操作标签

     1 //第一种类似jquery的操作,如果下面obj直接用selector比如"#id",得引用jquery,否则不需要。
     2 var template = angular.element(html);
     3 var element = $compile(template)($scope);
     4 var obj = document.getElementById();
     5 angular.element(obj).append(element);
     6  
     7 //第二种改变域数据的操作
     8 <p><span ng-repeat="number in data">{{number}}</span></p>
     9 $scope.data = [1, 2, 3];
    10 $timeout(function(){
    11     $scope.data.pop();
    12     $scope.data.push(4);
    13 }, 3000);

    2:控制html标签的class

     1 //css
     2 .active{background-color: red;}
     3 
     4 //html
     5 <button ng-click="showActive()">test</button>
     6 <p ng-class="{'active':active}">test</p>
     7 
     8 //JavaScript
     9 $scope.showActive=function(){
    10     $scope.active = !$scope.active;
    11 }

    3:controller中使用全局变量

    1 angular.module('app',[])
    2 .factory('flag', function() {
    3     return false;
    4 }).controller("testCtrl", function(flag){
    5     $scope.flag = flag;
    6 });

    4:$modal传参数给controller,这样方便把一个controller中的scope传给另一个controller调用。

    1 $modal.open({
    2     templateUrl: "/templates/menu/menuModal.html",
    3     controller: 'MenuUpdateCtrl',
    4     resolve:{
    5         pscope: function(){ return $scope; }
    6     }
    7 });
  • 相关阅读:
    N-Queens
    Pow(x, n)
    Maximum Subarray
    Spiral Matrix
    Jump Game
    Merge Intervals
    Insert Interval
    Length of Last Word
    Spiral Matrix II
    Amazon 面经
  • 原文地址:https://www.cnblogs.com/chenhao1990/p/4628909.html
Copyright © 2020-2023  润新知