小编use*_*589的帖子

这个Angular JS代码片段如何工作?

为什么以下代码片段在Angular JS中有效?

var app = angular.module('store',[]); 



(function(){
    app.controller('StoreController',function(){
        this.blabla = student;
    });
})();

var student = 
{
    name:"Abc Def",
    rollNumber:12,
    isBrilliant: true,
    isMale:false,
    isFemale: false,
    istest:true
};
Run Code Online (Sandbox Code Playgroud)

即使student在使用它并且student没有悬挂的功能之后仍然为什么上述功能仍然有效?

但与上面的例子相比,这个:

(function(){
        console.log("Name is :"+student);
    })();

    var student = {
        name:"xyz"
    };
Run Code Online (Sandbox Code Playgroud)

显示student作为undefined意味着它没有悬挂.

javascript debugging hoisting angularjs

4
推荐指数
2
解决办法
57
查看次数

了解Angularjs中指令优先级如何工作

app.js 是:

var app = angular.module('myApp',[]);
app.directive('myDirective2', function () {
    return{
        restrict: 'A',
        priority: 100,
        //template:"<h1>myDirective2</h1>",
        controller: function ($scope, $element, $transclude,$timeout) {
            //$scope.name = "executed myDirective2";
            $timeout(function () {
                $scope.name = "executed myDirective2";
            }, 3000);
        }
    };
});

app.directive('myDirective3', function () {
    return{
        restrict: 'A',
        priority: 200,
        //template:"<h1>myDirective3</h1>",
        controller: function ($scope, $element, $transclude, $timeout) {
            $timeout(function () {
                $scope.name = "executed myDirective3";
            }, 3000);
        }
    };
});
Run Code Online (Sandbox Code Playgroud)

index.html是:

<!DOCTYPE html>
<html ng-app="myApp">
    <head>
        <script src="js/angular.js" type="text/javascript"></script>
        <script src="js/app.js" …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs

4
推荐指数
1
解决办法
1万
查看次数

为什么不能访问控制器内部的这个函数和属性?

app2.js

(function(){
    var app = angular.module("panel",[]);
    app.controller('PanelController',function(){
          this.tab = 1;

          this.setTab = function(setTab){
                this.tab = setTab;
          };


    });

})();
Run Code Online (Sandbox Code Playgroud)

而且view是:

<html ng-app="panel">

<head>
    <link rel="stylesheet" type="text/css" href="bootstrap.min.css">
    <script type="text/javascript" src="angular.js"></script>
    <script type="text/javascript" src="app2.js"></script>\
    <style type="text/css">
    li{
        width:100px;
    }

    </style>
</head>

<body>

<section ng-controller="PanelController as panel">
    <ul class="nav nav-pills" >
        <li ng-class="{active:tab === 1}"><a ng-click="panel.setTab(1)" href="#">1</a></li>
        <li ng-class="{active:tab === 2}"><a ng-click="tab = 2" href="#">2</a></li>
        <li ng-class="{active:tab === 3}"><a ng-click="tab = 3" href="#">3</a></li>
        <li ng-class="{active:tab === 4}"><a ng-click="tab = 4" …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs

3
推荐指数
1
解决办法
63
查看次数

有人能解释这个控制台输出吗?

当我跑进去的时候 console

console.log("1");
setTimeout(function(){console.log("2");},3000);
console.log("3");
setTimeout(function(){console.log("4");},1000);
Run Code Online (Sandbox Code Playgroud)

我明白了:

在此输入图像描述

3之前和之后用蓝色写的数字是多少4

javascript debugging

2
推荐指数
2
解决办法
58
查看次数

为什么(char)433在c ++中等于-79'+ - '?

当我输入演员时433,char我得到了这个.如何433等于-79同时ASCII进行4&352&51分别按这个表.

c++ debugging c++11

1
推荐指数
1
解决办法
66
查看次数

以e结尾的单词的正则表达式

为什么e$与以e?结尾的单词不匹配?
示例@RegExr.com

regex pcre

1
推荐指数
1
解决办法
5524
查看次数

标签 统计

javascript ×4

angularjs ×3

debugging ×3

c++ ×1

c++11 ×1

hoisting ×1

pcre ×1

regex ×1