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

angular.js - 動態(tài)修改 directive 的templateUrl 只有在controller中生效,在directive中操作不生效
迷茫
迷茫 2017-05-15 17:06:15
0
1
579

//在controller中呼叫changeContentUrl 頁面範本可以更換. 但在下方homeAction點擊事件中操作url 不生效
var home = angular.module("home", [ "common" ]);

    home.controller("homeCtrl", function($scope, commonFactory) {
    
        $scope.contentUrl = "template/userInfo";
        $scope.changeContentUrl = function(contentUrl) {
             console.log(contentUrl);
            $scope.contentUrl = "adada"; 
        };
    });
    home.directive("content", function() {
        return {
            restrict : "E",
            template : "<p ng-include='getContentUrl()'></p>",
            link : function($scope, $element, $attr) {
                $scope.getContentUrl = function() {
                    return $attr.url;
                };
            }
        };
    });
home.directive("homeAction",function(commonFactory){
        return function($scope,element,attrs){
                var node =  element.find("li");
                node.on("click",function(event){
                    var url = $(event.target).attr("url");
                    $scope.contentUrl=url;
                    console.log($scope.contentUrl);
                });
            
        };
    });
迷茫
迷茫

業(yè)精于勤,荒于嬉;行成于思,毀于隨。

全部回覆(1)
巴扎黑

homeAction 有問題:

home.directive("homeAction",function(commonFactory){
    return function($scope,element,attrs){
        var node =  element.find("li");
        node.on("click",function(event){
            var url = $(event.target).attr("url");
            $scope.contentUrl=url;
            console.log($scope.contentUrl);
        });
    };
});

function(commonFactory){ 沒有傳回 directive 的設(shè)定訊息,需要傳回 JSON。

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