com.android.support:appcompat-v7:23.4.0 and com.android.support:recyclerview-v7:21.1.2

These are the correct version that you can add in your build.gradle according to the API needs.

API 21:

compile 'com.android.support:appcompat-v7:21.0.1'
compile 'com.android.support:recyclerview-v7:21.0.1'

OR

compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.android.support:recyclerview-v7:21.0.2'

OR

compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'

API 22:

compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:recyclerview-v7:22.0.0'

API 23:

compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'

AngularJS使用ng-repeat不更细View

今天在使用angularJS开发一个上传图片的功能,但是遇到了view不更新的问题,查了国内大部分网站,发现很多人都出现过这个问题,但是他们一般都是出现在请求数据中,我的项目全部都是使用promise对象处理的,所以没有出现过他们出现的问题,但是上传图片是没有数据传输的(因为我意图是在本地裁剪图片);

如果有像我这样子的,可以使用:

$scope.$apply();
通知视图更新,但是这不是一个好的习惯。

原文:
$scope.$apply(function() {
  $scope.msgs = newMsgs;
});

That is telling Angular that you’ve modified something it needs to know about from a context that it doesn’t know about (the jQuery ajax call in this case).

There are some valid uses of $scope.$apply(), such as in event handlers, but most other times it is a sign of bad practices. You should definitely be using Angular’s $http for ajax calls.

 

 

 

angularjs的自定义directive指令的绑定策略scope:”@”、”=”、”&”

通常我们知道指令默认是可以跟外界通信的.比如:

<div ng-controller="mytest">
    <test></test>
</div>

test自定义指令是可以访问到mytest控制器的scope
要想把test自定义指令独立作用域,也就是说跟mytest切断关系:可以加上指令的参数scope:{},这样就能做到互不相干了
但是也不可能完成切断关系,总会有某些东西要互相交互,如果想跟mytest控制器的某个scope属性交互,就要用绑定策略

下面来介绍三种绑定策略的做法

1.@符号
“@”是通过DOM的属性来跟mytest控制器交互绑定一起

<div ng-controller="mytest">
    <test></test>
</div>

 

app.controller("mytest", function ($scope) {
    $scope.name = "jack";
    $scope.age = 25;
});
app.directive("test",function(){
    return {
        restrict : "E",
        template : '<div name="{{name}}"></div>',
        replace : true,
        scope : {
            name : "@"
        },
        controller : function($scope){
            console.log($scope.name);  //"jack"
            console.log($scope.age);   //age是undefined,因为没有跟mytest进行交互
        },
        link : function ($scope) {
            console.log($scope.name); //"jack"
            console.log($scope.age);  //age是undefined,因为没有跟mytest进行交互
        }
    }
});

重点:
scope : {
name : “@”
}
scope对象声明了一个属性name,然后在DOM元素的属性加上一个name,(注意两边的名字必须要一致)这样就可以进行交互操作
点击查看完整代码

2.=符号
“=”有双重绑定的功能,比如mytest控制器与test子指令进行双重绑定(单个字符串、对象都是有效的)下面代码用对象来演示

<div ng-controller="mytest">
    父:<input type="text" ng-model="data.name" />
    <test></test>
</div>

 

app.controller("mytest", function ($scope) {
    $scope.data = {
        name : "jack",
        age : 25
    }
});
app.directive("test",function(){
    return {
        restrict : "E",
        template : '<div data="data">子指令:<input ng-model="data.name" /></div>',
        replace : true,
        scope : {
            data : "="
        },
        controller : function($scope){
            console.log($scope.data);  //Object {name: "jack", age: 25}
        },
        link : function ($scope) {
            console.log($scope.data); //Object {name: "jack", age: 25}
        }
    }
});

3.&符号
“&”的意思是子指令能调用父控制器的方法,这里的指令template元素点击调用控制器的getName方法

<div ng-controller="mytest">
    <test></test>
</div>

 

app.controller("mytest", function ($scope) {
    $scope.getName = function(){
        console.log("jack");
    }
});
app.directive("test",function(){
    return {
        restrict : "E",
        template : '<div get-name="getName()">子指令:<a href="javascript:void(0)" ng-click="getName()">点击调用父方法</a></div>',
        replace : true,
        scope : {
            getName : "&"
        },
        controller : function($scope){
            $scope.getName();  //"jack"
        },
        link : function ($scope) {
            $scope.getName(); //"jack"
        }
    }
});
12
 
Copyright © 2008-2021 lanxinbase.com Rights Reserved. | 粤ICP备14086738号-3 |