小编ian*_*a89的帖子

从AngularJS中的父控制器调用指令的方法

我正在使用带有别名控制器模式的AngularJS.我无法从父控制器访问(或者我不知道如何)指令方法.

我的控制器中有一个函数应该调用一个指令方法,但这个指令方法在this控制器值内不可用.

这就是我所拥有的.我做错了什么?

JS

angular.module('myApp', []).

controller('MyCtrl', function(){
  this.text = 'Controller text';

  this.dirText = 'Directive text';

  this.click = function(){
    this.changeText();
  }
})

.directive('myDir', function(){
  return {
     restrict: 'E',
     scope: {
       text: '='
     },
     link: function(scope, element, attrs){
       scope.changeText = function(){
         scope.text = 'New directive text';
       };
     },
     template: '<h2>{{text}}</h2>'
  };
});
Run Code Online (Sandbox Code Playgroud)

HTML

<div ng-app="myApp">
  <div ng-controller="MyCtrl as ctrl">
    <h1>{{ctrl.text}}</h1>
    <my-dir text="ctrl.dirText"></my-dir>
    <button ng-click="ctrl.click()">Change Directive Text</button>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

这里有代码的codepen.

javascript events angularjs angularjs-directive angularjs-controller

26
推荐指数
3
解决办法
5万
查看次数

vue js如何设置选择的选项值

我正在使用vue js为我的应用程序选择输入..我需要设置默认值应该在下拉中选择,而在更改时我想调用两个函数..

我是vue js的新手..

我的代码:

var listingVue = new Vue({

el: '#mountain',

data:{
        formVariables: { 
            country_id: '',
            mountain_id: '',
            peak_id: ''
        },
        countrylist:[],
        mountainlist:[],

},         

ready: function() {

    var datas = this.formVariables;
    this.getCountry();     

},

methods: {

    getCountry: function()
        {

            this.$http.get(baseurl+'/api/v1/device/getCountry',function(response)
            {
                this.$set('countrylist',response.result);      

                //alert(jQuery('#country_id').val());              
            });
        },
    getMountain: function(country_id)
        {
            var datas = this.formVariables;
            datas.$set('country_id', jQuery('#country_id').val() );
            postparemeters = {country_id:datas.country_id};
            this.$http.post(baseurl+'/api/v1/site/getMountain',postparemeters,function(response)
            {
                if(response.result)
                    this.$set('mountainlist',response.result);
                else
                    this.$set('mountainlist','');
            });
        },  
Run Code Online (Sandbox Code Playgroud)

});

 <select 
                    class="breadcrumb_mountain_property" 
                    id="country_id" 
                    v-model="formVariables.country_id" 
                    v-on="change:getMountain(formVariables.country_id);">
                <option 
                  v-repeat = "country: countrylist" 
                  value="@{{country.id}}" >
                  @{{country.name}} …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js

10
推荐指数
3
解决办法
3万
查看次数

为什么jQuery show()不起作用?

我正在使用jQuery隐藏div via hide().

然后当点击链接时它会显示div,但由于某种原因它不会停留.它将显示为ms然后消失.

HTML

<div id="introContent">
    <h1 id="introText">Welcome</h1>
    <p id="introParagraph">I create <strong>Responsive</strong>, <strong>Interactive</strong>, <strong>Beautiful</strong> Mobile ready Websites.
        Every Website is created from scratch for each client so no Two Projects are alike.
        Please read more about my Company and our work.
        "High Quality Work at Affordable Prices"
    </p>
</div>
Run Code Online (Sandbox Code Playgroud)

jQuery的

$(function() {
    $("#introContent").hide();
    $("#intro").click(function () { //$(#intro) is a link in my nav bar 
        $("#introContent").show();
    });
});
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery

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

CSS转换:rotate vs rotationZ

我想知道css转换函数rotate和之间的区别rotateZ

如果我将这些属性(具有相同的值)应用于两个不同的元素,则会得到相同的结果:

的HTML

<div class="rotateZ">
  <img src="http://ohdoylerules.com/content/images/css3.svg"/>
  <h3>RotateZ</h3>
</div>

<div class="rotate">
  <img src="http://ohdoylerules.com/content/images/css3.svg"/>
  <h3>Rotate</h3>
</div>
Run Code Online (Sandbox Code Playgroud)

的CSS

.rotateZ {
  transform: rotateZ(180deg);
}

.rotate {
  transform: rotate(180deg);
}
Run Code Online (Sandbox Code Playgroud)

css3 css-transforms

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

Arduino超声波传感器总是返回0

我正在Arduino UNO中做一个连接超声波传感器(HC-SR04)的基本项目,该传感器应该在串行监视器中打印最近物体的距离,但它总是打印 0。

这是我的代码:

long distance;
long time;

void setup(){
  Serial.begin(9600);
  pinMode(4, OUTPUT); 
  pinMode(2, INPUT); 
}

void loop(){
  digitalWrite(2,LOW);
  delayMicroseconds(5);
  digitalWrite(2, HIGH);
  delayMicroseconds(10);

  time = pulseIn(4, HIGH);
  distance = int(0.017*time); 

  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm.");
  delay(1000);
}
Run Code Online (Sandbox Code Playgroud)

这是面包板:

在此输入图像描述

arduino arduino-ultra-sonic

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

有一种方法可以使用NEWID函数生成GUID列表吗?

我需要在SQL Server 2008 R2中创建一个GUID列表,我正在使用该NEWID()功能.

这是我正在尝试但我只得到一个ID:

SELECT TOP 100 NEWID() 
Run Code Online (Sandbox Code Playgroud)

我是SQL Server的新手,我不知道是否有办法做到这一点,或者是一种创建循环的方法.

我不需要坚持那些GUID,我只想在屏幕上显示它们.

sql sql-server sql-server-2008-r2

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

是否可以为特定的 HTTP 方法添加快速中间件?

我想添加一个必须在发生请求时触发的Express中间件POST(与路由 URL 无关)。

我认为这样的事情应该有效:

app.use(function (req, res, next) {

  if (req.method === 'POST') {
    console.log('Time:', Date.now());
  }

});
Run Code Online (Sandbox Code Playgroud)

但我想知道Express是否有开箱即用的功能来处理这些场景。

node.js express

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

错误500 Web请求无法抓取WebSite

我用浏览器访问网站没有问题,但是当我以编程方式尝试访问网站进行抓取时,我收到以下错误.

The remote server returned an error: (500) Internal Server Error.
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的代码.

using System.Net;

string strURL1 = "http://www.covers.com/index.aspx";
WebRequest req = WebRequest.Create(strURL1);

// Get the stream from the returned web response
StreamReader stream = new StreamReader(req.GetResponse().GetResponseStream());
System.Text.StringBuilder sb = new System.Text.StringBuilder();
string strLine;
// Read the stream a line at a time and place each one
while ((strLine = stream.ReadLine()) != null)
{
  if (strLine.Length > 0)
    sb.Append(strLine + Environment.NewLine);
}

stream.Close();
Run Code Online (Sandbox Code Playgroud)

这个让我难过.TIA

c# httpwebrequest

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

禁用带下划线的锚标记的内部元素的下划线

我们可以禁用带下划线的锚标记的内部跨度元素的下划线吗?如果可能,请告诉我如何?

 <a>hello<span>praveen</span</a>

 <style type="text/css>
     a{
        text-decoration:underline;
     }
     a span{
        text-decoration:none;
     }
 </style>
Run Code Online (Sandbox Code Playgroud)

html css

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

与window.onload()的JS问题

我正在将一个应用程序集成到Shopify中.我目前正在测试我们的外部js文件.我们看到一些奇怪的结果.当我使用这段代码时:

jQuery(document).ready(function(){
    console.log("hi");
});
Run Code Online (Sandbox Code Playgroud)

"嗨!" 出现在控制台中.但是当我使用时:

window.onload = function() {
    console.log("hi!");
}
Run Code Online (Sandbox Code Playgroud)

...什么都没发生.我推测还有另一个onload事件处理程序,它稍后发生并覆盖我的,但即使我尝试在js中执行jquery等效:

window.DOMContentLoaded = function() {
    console.log("hi!");
}
Run Code Online (Sandbox Code Playgroud)

...仍然没有任何反应.任何想法为什么会这样,有没有办法让我的脚本与等效的(文档).ready一起运行而不必诉诸jQuery(因为有些客户可能没有运行它)?

javascript jquery onload

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