国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

angular.js - angular的指令如何賦值給控制的值呢?
曾經(jīng)蠟筆沒有小新
曾經(jīng)蠟筆沒有小新 2017-05-15 17:05:14
0
3
665

比如,我在主控制器中有一個(gè)參數(shù)是: $scope.datas

然后,我在這里有一個(gè)指令,在指控的控制器上請求數(shù)據(jù),然后想要賦值給主控制器的 $scope.datas。
如何得逞呢?

如,指令:


app.directive('profitSearch', function () {

    return {

        restrict: 'AE',
        scope: {
            datas: "="
        },
        templateUrl: "/templates/profitSearch.jsp",
        controller: function ($scope, $http) {

        $http({
                    url: 'doSearch.req',
                    method: 'POST',
                    data: $scope.searchObject
                }).success(function (response, header, config, status) {

                    $scope.datas = response.content;

                }).error(function (response, header, config, status) {


                });

}

指令在頁面直接應(yīng)用:

<profit-search></profit-search>

但是這樣賦值是錯(cuò)誤的:
$compile:nonassign

怎么破呢?我上面不是用了雙向綁定了嗎?

曾經(jīng)蠟筆沒有小新
曾經(jīng)蠟筆沒有小新

全部回復(fù)(3)
曾經(jīng)蠟筆沒有小新

你指令上使用的時(shí)候沒有賦值, 試試改成這樣。

 scope: {
    datas: "=?"
 },

或者給指令賦值

<profit-search datas="datas"></profit-search>

https://docs.angularjs.org/error/$compile/nonassign

僅有的幸福

你有必要寫指令么?亂來!胡亂寫指令耽誤時(shí)間不說,性能也好不了。直接在service里邊寫個(gè)請求應(yīng)該就能解決問題了。

Peter_Zhu

雷雷

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板